工事報告書	新規
工事報告書	元請
完成工事	フィルタ
請求
見積8
印刷

IME
プルダウン
カレンダー
ますく
フォーかつ
登録時のフォーカス
 TabIndex="1"
数値	未入力でコンバータエラー
労務費たぶ
ふり仮名
Maxlenght

ToDo: Master
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tact.Data.Entity;
using Tact.Models;
using Tact.Services;

namespace Tact
{
    /// <summary>
    /// マスターを提供します。
    /// </summary>
    public class Master
    {
        #region Constructor
        /// <summary>
        /// 新しいインスタンスを初期化します。
        /// </summary>
        static Master()
        {
            Master.Tax = new TaxService();
        }
        #endregion

        #region Property
        /// <summary>
        /// 税を取得または設定します。
        /// </summary>
        public static TaxService Tax { get; set; }
        #endregion

        #region Method
        /// <summary>
        /// オフィスのコレクションを取得します。
        /// </summary>
        /// <returns>結果。</returns>
        private static List<Office> Offices()
        {
            using (var context = new DatabaseContext())
            {
                return context.Offices.ToList();
            }
        }

        /// <summary>
        /// オフィスのコレクションを取得します。
        /// </summary>
        /// <param name="required">必須であるかどうかを示す値。</param>
        /// <returns>結果。</returns>
        public static List<Office> Offices(bool required = false)
        {
            var source = Cached.Offices
                .OrderBy(entity => entity.Id)
                .ToList();

            if (!required) source.Insert(0, new Office());

            return source;
        }

        /// <summary>
        /// 設定を取得します。
        /// </summary>
        /// <param name="user">ユーザー。</param>
        /// <returns>結果。</returns>
        public static Setting Setting(User user)
        {
            return Master.Setting(user.OfficeId);
        }

        /// <summary>
        /// 設定を取得します。
        /// </summary>
        /// <param name="user">ユーザー。</param>
        /// <returns>結果。</returns>
        internal static Setting Setting(string officeId)
        {
            using (var context = new DatabaseContext())
            {
                return context.Settings.Single(entity => entity.OfficeId == officeId);
            }
        }

        /// <summary>
        /// ユーザーのコレクションを取得します。
        /// </summary>
        /// <param name="user">ユーザー。</param>
        /// <param name="required">必須であるかどうかを示す値。</param>
        /// <returns>結果。</returns>
        public static List<User> Users(User user, bool required = false)
        {
            using (var context = new DatabaseContext())
            {
                var source = context.Users
                    .Where(entity => entity.OfficeId == user.OfficeId && entity.Id != User.System.Id && entity.IsEnabled)
                    .OrderBy(entity => entity.Id)
                    .ToList();

                if (!required) source.Insert(0, new User());

                return source;
            }
        }

        /// <summary>
        /// 取引先のコレクションを取得します。
        /// </summary>
        /// <param name="type">タイプ。</param>
        /// <param name="required">必須であるかどうかを示す値。</param>
        /// <returns>結果。</returns>
        public static List<Customer> Customers(CustomerType type, bool required = false)
        {
            return Customers(new CustomerType[] { type }, false);
        }

        /// <summary>
        /// 取引先のコレクションを取得します。
        /// </summary>
        /// <param name="types">タイプのコレクション。</param>
        /// <param name="required">必須であるかどうかを示す値。</param>
        /// <returns>結果。</returns>
        public static List<Customer> Customers(IEnumerable<CustomerType> types, bool required = false)
        {
            using (var context = new DatabaseContext())
            {
                var source = context.Customers
                    .Where(entity => types.Contains(entity.Type))
                    .OrderBy(entity => entity.Id)
                    .ToList();

                if (!required) source.Insert(0, new Customer());

                return source;
            }
        }

        /// <summary>
        /// コードのコレクションを取得します。
        /// </summary>
        /// <returns>結果。</returns>
        private static List<Code> Codes()
        {
            using (var context = new DatabaseContext())
            {
                return context.Codes.ToList();
            }
        }

        /// <summary>
        /// 宛名のコレクションを取得します。
        /// </summary>
        /// <param name="required">必須であるかどうかを示す値。</param>
        /// <returns>結果。</returns>
        public static List<Code> Suffixes(bool required = false)
        {
            var source = Cached.Codes
                .Where(entity => entity.Category == 5)
                .OrderBy(entity => entity.Value)
                .ToList();

            if (!required) source.Insert(0, new Code());

            return source;
        }

        /// <summary>
        /// 単位のコレクションを取得します。
        /// </summary>
        /// <param name="required">必須であるかどうかを示す値。</param>
        /// <returns>結果。</returns>
        public static List<Code> Units(bool required = false)
        {
            var source = Cached.Codes
                .Where(entity => entity.Category == 1)
                .OrderBy(entity => entity.Value)
                .ToList();

            if (!required) source.Insert(0, new Code());

            return source;
        }

        /// <summary>
        /// オーダーのタイプのコレクションを取得します。
        /// </summary>
        /// <param name="required">必須であるかどうかを示す値。</param>
        /// <returns>結果。</returns>
        public static List<Code> OrderTypes(bool required = false)
        {
            var source = Cached.Codes
                .Where(entity => entity.Category == 2)
                .OrderBy(entity => entity.Value)
                .ToList();

            if (!required) source.Insert(0, new Code());

            return source;
        }

        /// <summary>
        /// オーダーの用途のコレクションを取得します。
        /// </summary>
        /// <param name="required">必須であるかどうかを示す値。</param>
        /// <returns>結果。</returns>
        public static List<Code> OrderUses(bool required = false)
        {
            var source = Cached.Codes
                .Where(entity => entity.Category == 3)
                .OrderBy(entity => entity.Value)
                .ToList();

            if (!required) source.Insert(0, new Code());

            return source;
        }

        /// <summary>
        /// 税のコレクションを取得します。
        /// </summary>
        /// <returns>結果。</returns>
        private static List<Tax> Taxes()
        {
            using (var context = new DatabaseContext())
            {
                return context.Taxes.ToList();
            }
        }
        #endregion

        #region Cached
        /// <summary>
        /// キャッシュされている、マスターを提供します。
        /// </summary>
        public class Cached
        {
            #region Field
            /// <summary>
            /// 同期オブジェクトを表します。
            /// </summary>
            private static object sync = new object();

            /// <summary>
            /// コードのコレクションを表します。
            /// </summary>
            private static ICollection<Code> codes;

            /// <summary>
            /// オフィスのコレクションを表します。
            /// </summary>
            private static ICollection<Office> offices;

            /// <summary>
            /// 税のコレクションを表します。
            /// </summary>
            private static ICollection<Tax> taxes;
            #endregion

            #region Property
            /// <summary>
            /// コードのコレクションを取得します。
            /// </summary>
            public static IEnumerable<Code> Codes
            {
                get
                {
                    lock(sync) { if (codes == null) codes = Master.Codes(); }

                    return codes;
                }
            }

            /// <summary>
            /// オフィスのコレクションを取得します。
            /// </summary>
            public static IEnumerable<Office> Offices
            {
                get
                {
                    lock(sync) { if (offices == null) offices = Master.Offices(); }

                    return offices;
                }
            }

            /// <summary>
            /// 税のコレクションを取得します。
            /// </summary>
            public static IEnumerable<Tax> Taxes
            {
                get
                {
                    lock(sync) { if (taxes == null) taxes = Master.Taxes(); }

                    return taxes;
                }
            }
            #endregion
        }
        #endregion
    }
}

ToDo: Generic.xaml

<ResourceDictionary
    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"
    xmlns:Controls="clr-namespace:Tact.Windows.Controls">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.KeyTipControl.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.Ribbon.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonApplicationMenu.xaml"/><!-- ToDo -->
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonApplicationMenuItem.xaml"/><!-- ToDo -->
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonApplicationSplitMenuItem.xaml"/><!-- ToDo -->
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonButton.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonCheckBox.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonComboBox.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonContextMenu.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonContextualTabGroup.xaml"/><!-- -->
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonContextualTabGroupItemsControl.xaml"/><!-- -->
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonControl.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonControlGroup.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonFilterMenuButton.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonGallery.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonGalleryCategory.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonGalleryItem.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonGroup.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonMenuButton.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonMenuItem.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonQuickAccessToolBar.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonRadioButton.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonSeparator.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonSplitButton.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonSplitMenuItem.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonTab.xaml"/><!-- -->
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonTabHeader.xaml"/><!-- -->
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonTabHeaderItemsControl.xaml"/><!-- -->
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonTextBox.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonToggleButton.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonToolTip.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonTwoLineText.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RibbonWindow.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.StatusBar.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.SystemButton.xaml"/>

        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.Button.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.CheckBox.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.ComboBox.xaml"/>
        <!--<ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.Expander.xaml"/>-->
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.GridSplitter.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.GroupBox.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.Image.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.Label.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.ListBox.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.PasswordBox.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.ProgressBar.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RadioButton.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.RepeatButton.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.ScrollViewer.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.Slider.xaml"/>
        <!--<ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.TextBlock.xaml"/>-->
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.TextBox.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.ToggleButton.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.Tooltip.xaml"/>
        <ResourceDictionary Source="pack://application:,,,/Tact.Windows.Controls;component/Themes/Generic.Window.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <!-- DatePicker -->
    <Style TargetType="{x:Type DatePicker}" BasedOn="{StaticResource {x:Type DatePicker}}">
        <Style.Resources>
            <Style TargetType="{x:Type Button}">
                <Setter Property="Margin" Value="0,-1,0,0"/>
                <Setter Property="MinHeight" Value="0"/>
            </Style>
        </Style.Resources>
        <Setter Property="VerticalAlignment" Value="Top"/>
        <Setter Property="MinHeight" Value="24"/>
        <Setter Property="Height" Value="24"/>
        <Setter Property="Background" Value="{DynamicResource ControlBackground}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource ControlBorder}"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Foreground" Value="{DynamicResource ControlForeground}"/>
        <Setter Property="Padding" Value="2,2,2,2"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
    </Style>

    <!-- Dialog -->
    <Style x:Key="DialogStyle" TargetType="{x:Type Window}" BasedOn="{StaticResource {x:Type Window}}">
        <Setter Property="BorderBrush" Value="{DynamicResource AccentBackground}"/>
        <!--<Setter Property="Icon" Value="/Icon.ico"/>-->
        <Setter Property="ResizeMode" Value="NoResize"/>
        <Setter Property="SizeToContent" Value="WidthAndHeight"/>
        <Setter Property="MaxWidth" Value="1024"/>
        <Setter Property="MaxHeight" Value="720"/>
    </Style>

    <Style x:Key="DialogHeaderStyle" TargetType="{x:Type StackPanel}">
        <Setter Property="DockPanel.Dock" Value="Top"/>
        <Setter Property="Margin" Value="16,0"/>
    </Style>

    <Style x:Key="DialogContentStyle" TargetType="{x:Type DockPanel}">
        <Setter Property="Margin" Value="16,0"/>
    </Style>

    <Style x:Key="DialogResponsiveStyle" TargetType="{x:Type Controls:ResponsiveGrid}" BasedOn="{StaticResource {x:Type Controls:ResponsiveGrid}}">
        <Setter Property="Margin" Value="16,3"/>
    </Style>

    <Style x:Key="DialogFooterStyle" TargetType="{x:Type StackPanel}">
        <Style.Resources>
            <Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
                <Setter Property="Margin" Value="3"/>
                <Setter Property="MinWidth" Value="80"/>
            </Style>
        </Style.Resources>
        <Setter Property="DockPanel.Dock" Value="Bottom"/>
        <Setter Property="HorizontalAlignment" Value="Right"/>
        <Setter Property="Margin" Value="16,6,16,16"/>
        <Setter Property="Orientation" Value="Horizontal"/>
    </Style>

    <Style x:Key="CopyrightStyle" TargetType="{x:Type TextBlock}">
        <Setter Property="DockPanel.Dock" Value="Bottom"/>
        <Setter Property="FontSize" Value="10"/>
        <Setter Property="Foreground" Value="{DynamicResource LightForeground}"/>
        <Setter Property="HorizontalAlignment" Value="Right"/>
        <Setter Property="Margin" Value="16,0,16,3"/>
    </Style>

    <!-- Content -->
    <Style x:Key="ContentGridStyle" TargetType="{x:Type Grid}">
        <Setter Property="Margin" Value="0,8,0,0"/>
    </Style>
    <Style x:Key="VerticalSplitterStyle" TargetType="{x:Type GridSplitter}" BasedOn="{StaticResource {x:Type GridSplitter}}">
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="HorizontalAlignment" Value="Center"/>
        <Setter Property="VerticalAlignment" Value="Stretch"/>
        <Setter Property="Width" Value="11"/>
    </Style>
    <Style x:Key="ContentBorderStyle" TargetType="{x:Type Border}">
        <Setter Property="Margin" Value="3,0,8,8"/>
    </Style>
    <Style x:Key="SeparatorBorderStyle" TargetType="{x:Type Border}">
        <Setter Property="BorderBrush" Value="{DynamicResource Separator}"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="Height" Value="1"/>
    </Style>

    <!-- TextBlock -->
    <Style x:Key="AsideStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
        <Setter Property="FontSize" Value="11"/>
        <Setter Property="Foreground" Value="{DynamicResource LightForeground}"/>
    </Style>
    <Style x:Key="AsideIndentStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource AsideStyle}">
        <Setter Property="Margin" Value="16,2,0,0"/>
    </Style>

    <!-- ListView -->
    <Style TargetType="{x:Type ListView}">
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="TextElement.Foreground" Value="{DynamicResource ControlForeground}"/>
        <Setter Property="Margin" Value="0,0,0,2"/>
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden"/>
        <Setter Property="SelectionMode" Value="Single"/>
    </Style>
    <Style TargetType="{x:Type GridViewColumnHeader}" BasedOn="{StaticResource {x:Type GridViewColumnHeader}}">
        <Setter Property="Foreground" Value="{DynamicResource LightForeground}"/>
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                    <Border
                        Background="Transparent"
                        BorderThickness="0,0,1,1"
                        BorderBrush="{DynamicResource Separator}">
                        <TextBlock
                            Text="{TemplateBinding Content}"
                            VerticalAlignment="Center"
                            Padding="6,4,6,2"
                            TextAlignment="Center"
                            Width="{TemplateBinding Width}"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="{x:Type ListViewItem}">
        <Setter Property="Margin" Value="0"/>
    </Style>
    <Style x:Key="ItemBorderStyle" TargetType="{x:Type Border}">
        <Setter Property="Background" Value="{DynamicResource ControlBackground}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource Separator}"/>
        <Setter Property="BorderThickness" Value="0,0,0,1"/>
        <Setter Property="Focusable" Value="True"/>
        <Setter Property="Padding" Value="6,3"/>
    </Style>

    <!-- ResponsiveGrid -->
    <Style TargetType="{x:Type Controls:ResponsiveGrid}">
        <Style.Resources>
            <Style TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}">
                <Setter Property="Width" Value="96"/>
            </Style>
            <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
                <Setter Property="Margin" Value="0,0,3,0"/>
            </Style>
            <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
                <Setter Property="Foreground" Value="{DynamicResource ControlForeground}"/>
                <Setter Property="Padding" Value="0,3,6,3"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
            </Style>
            <Style TargetType="{x:Type PasswordBox}" BasedOn="{StaticResource {x:Type PasswordBox}}">
                <Setter Property="Margin" Value="0,0,3,0"/>
            </Style>
            <Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource {x:Type ComboBox}}">
                <Setter Property="Margin" Value="0,0,3,0"/>
            </Style>
            <Style TargetType="{x:Type CheckBox}" BasedOn="{StaticResource {x:Type CheckBox}}">
                <Setter Property="Margin" Value="0,0,3,0"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
            </Style>
            <Style TargetType="{x:Type DatePicker}" BasedOn="{StaticResource {x:Type DatePicker}}">
                <Setter Property="Margin" Value="0,0,3,0"/>
            </Style>
            <Style TargetType="{x:Type DockPanel}">
                <Setter Property="ResponsiveGrid.ColumnSpan" Value="12,6,4,3"/>
                <Setter Property="Margin" Value="3,3,0,3"/>
                <Setter Property="VerticalAlignment" Value="Top"/>
            </Style>
        </Style.Resources>
        <Setter Property="Margin" Value="0"/>
    </Style>
    <Style x:Key="EmptyDockPanelStyle" TargetType="{x:Type DockPanel}">
        <Setter Property="Margin" Value="0"/>
    </Style>

    <!-- DataGrid -->
    <Style TargetType="{x:Type DataGrid}" BasedOn="{StaticResource {x:Type DataGrid}}">
        <Setter Property="AutoGenerateColumns" Value="False"/>
        <Setter Property="Background" Value="{DynamicResource ControlBackground}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource ControlBorder}"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="HorizontalGridLinesBrush" Value="{DynamicResource ControlBorder}"/>
        <Setter Property="VerticalGridLinesBrush" Value="{DynamicResource ControlBorder}"/>
        <Setter Property="CanUserAddRows" Value="False"/>
        <Setter Property="CanUserDeleteRows" Value="False"/>
        <Setter Property="CanUserReorderColumns" Value="False"/>
        <Setter Property="CanUserResizeColumns" Value="False"/>
        <Setter Property="CanUserResizeRows" Value="False"/>
        <Setter Property="CanUserSortColumns" Value="False"/>
        <Setter Property="Foreground" Value="{DynamicResource ControlForeground}"/>
        <Setter Property="HeadersVisibility" Value="Column"/>
        <Setter Property="SelectionUnit" Value="FullRow"/>
    </Style>

    <Style TargetType="{x:Type DataGridColumnHeader}" BasedOn="{StaticResource {x:Type DataGridColumnHeader}}">
        <Setter Property="Background" Value="{DynamicResource GrayBackground}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource ControlBorder}"/>
        <Setter Property="BorderThickness" Value="0,0,1,1"/>
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="Height" Value="23"/>
    </Style>

    <Style TargetType="{x:Type DataGridRowHeader}" BasedOn="{StaticResource {x:Type DataGridRowHeader}}">
        <Setter Property="Background" Value="{DynamicResource GrayBackground}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource ControlBorder}"/>
        <Setter Property="BorderThickness" Value="0,0,1,1"/>
    </Style>

    <Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource {x:Type DataGridRow}}">
        <Setter Property="Background" Value="{DynamicResource ControlBackground}"/>
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Background" Value="{DynamicResource ControlHighlightBackground}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource {x:Type DataGridCell}}">
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True">
                <Setter Property="Background" Value="{DynamicResource ControlHighlightBackground}"/>
                <Setter Property="Foreground" Value="{DynamicResource ControlForeground}"/>
            </Trigger>
            <Trigger Property="IsFocused" Value="True">
                <Setter Property="Background" Value="{DynamicResource ControlActiveBackground}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="FixedDataGridStyle" TargetType="{x:Type DataGrid}" BasedOn="{StaticResource {x:Type DataGrid}}">
        <Setter Property="BorderThickness" Value="1,0,1,0"/>
        <Setter Property="HeadersVisibility" Value="None"/>
        <Setter Property="SelectionMode" Value="Single"/>
        <Setter Property="HorizontalScrollBarVisibility" Value="Hidden"/>
        <Setter Property="VerticalScrollBarVisibility" Value="Visible"/>
    </Style>

    <Style x:Key="FooterDataGridStyle" TargetType="{x:Type DataGrid}" BasedOn="{StaticResource {x:Type DataGrid}}">
        <Style.Resources>
            <Style TargetType="{x:Type DataGridRow}" BasedOn="{StaticResource {x:Type DataGridRow}}">
                <Setter Property="Background" Value="{DynamicResource GrayBackground}"/>
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Background" Value="{DynamicResource GrayBackground}"/>
                        <Setter Property="Focusable" Value="False"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
            <Style TargetType="{x:Type DataGridCell}" BasedOn="{StaticResource {x:Type DataGridCell}}">
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Background" Value="{DynamicResource GrayBackground}"/>
                        <Setter Property="Focusable" Value="False"/>
                    </Trigger>
                    <Trigger Property="IsFocused" Value="True">
                        <Setter Property="Background" Value="{DynamicResource GrayBackground}"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Style.Resources>
        <Setter Property="Background" Value="{DynamicResource GrayBackground}"/>
        <Setter Property="BorderThickness" Value="1,0,1,0"/>
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="HeadersVisibility" Value="None"/>
        <Setter Property="IsReadOnly" Value="True"/>
        <Setter Property="SelectionMode" Value="Single"/>
        <Setter Property="HorizontalScrollBarVisibility" Value="Hidden"/>
        <Setter Property="VerticalScrollBarVisibility" Value="Visible"/>
    </Style>

    <Style x:Key="SummaryDataGridStyle" TargetType="{x:Type DataGrid}" BasedOn="{StaticResource FooterDataGridStyle}">
        <Setter Property="BorderThickness" Value="1,1,1,0"/>
    </Style>

    <Style x:Key="CellStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
        <Setter Property="Height" Value="23"/>
        <Setter Property="Padding" Value="3,4,3,3"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
    </Style>
    <Style x:Key="CellFirstStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource CellStyle}">
        <Setter Property="Height" Value="22"/>
        <!--<Setter Property="Padding" Value="3,1,3,1"/>-->
    </Style>
    <Style x:Key="CellSecondStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource CellStyle}">
        <!--<Setter Property="Height" Value="17"/>-->
        <!--<Setter Property="Padding" Value="3,1,3,1"/>-->
    </Style>
    <Style x:Key="RightCellStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource CellStyle}">
        <Setter Property="TextAlignment" Value="Right"/>
    </Style>

    <Style x:Key="TextCellStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextBoxCellStyle}">
        <Setter Property="BorderThickness" Value="0"/>
        <!--<Setter Property="MinHeight" Value="0"/>-->
        <Setter Property="VerticalContentAlignment" Value="Center"/>
    </Style>
    <Style x:Key="TextCellFirstStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextCellStyle}">
        <Setter Property="BorderBrush" Value="{DynamicResource Separator}"/>
        <Setter Property="BorderThickness" Value="0,0,0,1"/>
        <!--<Setter Property="Padding" Value="1,1,1,1"/>-->
    </Style>
    <Style x:Key="TextCellSecondStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextCellStyle}">
        <!--<Setter Property="Padding" Value="1,1,1,1"/>-->
    </Style>
    <Style x:Key="TextRightCellStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextCellStyle}">
        <Setter Property="TextAlignment" Value="Right"/>
    </Style>

    <Style x:Key="ComboBoxCellStyle" TargetType="{x:Type ComboBox}">
        <Setter Property="Margin" Value="3"/>
        <Setter Property="Foreground" Value="{DynamicResource ControlForeground}"/>
        <Setter Property="Selector.IsSynchronizedWithCurrentItem" Value="False"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
    </Style>
    <!--<Style x:Key="EditingComboBoxCellStyle" TargetType="{x:Type ComboBox}" BasedOn="{StaticResource ComboBoxCellStyle}">
        <Setter Property="Foreground" Value="{DynamicResource ControlForeground}"/>
        <Setter Property="Selector.IsSynchronizedWithCurrentItem" Value="False"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
    </Style>-->
</ResourceDictionary>

ToDo: Extensions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tact
{
    /// <summary>
    /// 拡張メソッドを提供します。
    /// </summary>
    public static partial class Extensions
    {
        #region Method
        /// <summary>
        /// 取引先のタイプに変換します。
        /// </summary>
        /// <param name="source">ソース。</param>
        /// <returns>結果。</returns>
        public static CustomerType ToCustomerType(this string source)
        {
            return (CustomerType)int.Parse(source.Substring(0, 1));
        }

        /// <summary>
        /// コストのタイプに変換します。
        /// </summary>
        /// <param name="source">ソース。</param>
        /// <returns>結果。</returns>
        public static CostType ToCostType(this string source)
        {
            return source.ToCustomerType().ToCostType();
        }

        /// <summary>
        /// 名称を取得します。
        /// </summary>
        /// <param name="source">ソース。</param>
        /// <returns>結果。</returns>
        public static string Name(this CustomerType source)
        {
            switch (source)
            {
                case CustomerType.Orderer:
                    return "受注先/元請";
                case CustomerType.Painting:
                    return "塗装工";
                case CustomerType.Outsourcee:
                    return "その他外注先";
                case CustomerType.Material:
                    return "材料品目";
                case CustomerType.Field:
                    return "現場経費項目";
                case CustomerType.Direct:
                    return "直用工経費項目";
                default:
                    throw new NotSupportedException();
            }
        }

        /// <summary>
        /// 名称を取得します。
        /// </summary>
        /// <param name="source">ソース。</param>
        /// <returns>結果。</returns>
        public static string Name(this DeductionNumber source)
        {
            switch (source)
            {
                case DeductionNumber.Empty:
                    return null;
                case DeductionNumber.Transfer:
                    return "振込手数料";
                case DeductionNumber.Membership:
                    return "豊友会 5/1000";
                default:
                    throw new NotSupportedException();
            }
        }

        /// <summary>
        /// コストのタイプに変換します。
        /// </summary>
        /// <param name="source">ソース。</param>
        /// <returns>結果。</returns>
        public static CostType ToCostType(this CustomerType source)
        {
            switch (source)
            {
                case CustomerType.Painting:
                case CustomerType.Outsourcee:
                    return CostType.Outsourcing;
                case CustomerType.Material:
                    return CostType.Material;
                case CustomerType.Field:
                    return CostType.Field;
                case CustomerType.Direct:
                    return CostType.Direct;
                default:
                    throw new NotSupportedException();
            }
        }

        /// <summary>
        /// 指定された文字数になるまで左側に0を埋め込みます。
        /// </summary>
        /// <param name="source">ソース。</param>
        /// <param name="length">文字数。</param>
        /// <returns>結果。</returns>

ToDo: Deduction

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tact.Models.DataAnnotations.Schema;
using Column = Tact.Models.DataAnnotations.Schema.ColumnAttribute;

namespace Tact.Models
{
    /// <summary>
    /// 控除を表します。
    /// </summary>
    public class Deduction : Record, IEquatable<Deduction>
    {
        #region Field
        /// <summary>
        /// ナンバーを表します。
        /// </summary>
        private int number;

        /// <summary>
        /// 名称を表します。
        /// </summary>
        private string name;
        #endregion

        #region Property
        /// <summary>
        /// オフィスIDを取得または設定します。
        /// </summary>
        [Key, Column(Type = SqlDbType.VarChar, Order = 0), MaxLength(2)]
        public string OfficeId { get; set; }

        /// <summary>
        /// オフィスを取得または設定します。
        /// </summary
        public virtual Office Office { get; set; }

        /// <summary>
        /// 年月を取得または設定します。
        /// </summary>
        [Key, Column(Type = SqlDbType.VarChar, Order = 1), MaxLength(6)]
        public string YearMonth { get; set; }

        /// <summary>
        /// 取引先IDを取得または設定します。
        /// </summary>
        [Key, Column(Type = SqlDbType.VarChar, Order = 2), MaxLength(6)]
        public string CustomerId { get; set; }

        /// <summary>
        /// 取引先を取得または設定します。
        /// </summary
        public virtual Customer Customer { get; set; }

        /// <summary>
        /// ナンバーを取得または設定します。
        /// </summary>
        [Key, Column(Type = SqlDbType.Int, Order = 3)]
        public int Number
        {
            get { return this.number; }
            set { this.number = value; if (this.Required) this.name = ((DeductionNumber)value).Name(); }
        }

        /// <summary>
        /// 必須かどうかを示す値を取得します。
        /// </summary>
        [NotMapped]
        public bool Required
        {
            get { return (int)DeductionNumber.Empty <= this.Number; }
        }

        /// <summary>
        /// 名称を取得または設定します。
        /// </summary>
        [Column(Type = SqlDbType.NVarChar), MaxLength(64)]
        public string Name
        {
            get { return this.name; }
            set { if (!this.Required) this.name = value; }
        }

        /// <summary>
        /// 値を取得または設定します。
        /// </summary>
        [Column(Type = SqlDbType.Float)]
        public double? Value { get; set; }
        #endregion

        #region Method
        /// <summary>
        /// リフレッシュします。
        /// </summary>
        public override void Refresh()
        {
            this.Office = null;
            this.Customer = null;
        }

        /// <summary>
        /// 指定されたインスタンスと等しいかどうかを示します。
        /// </summary>
        /// <param name="value">値。</param>
        /// <returns>等しいかどうかを示す値。</returns>
        public bool Equals(Deduction value)
        {
            if (value == null) return false;

            if (object.ReferenceEquals(this, value)) return true;

            return
                object.Equals(this.OfficeId, value.OfficeId) &&
                object.Equals(this.YearMonth, value.YearMonth) &&
                object.Equals(this.CustomerId, value.CustomerId) &&
                object.Equals(this.Number, value.Number);
        }

        /// <summary>
        /// 指定されたインスタンスと等しいかどうかを示します。
        /// </summary>
        /// <param name="value">値。</param>
        /// <returns>等しいかどうかを示す値。</returns>
        public override bool Equals(object value)
        {
            return this.Equals(value as Deduction);
        }

        /// <summary>
        /// ハッシュコードを取得します。
        /// </summary>
        /// <returns>結果。</returns>
        public override int GetHashCode()
        {
            return this.GetHashCode(
                this.OfficeId,
                this.YearMonth,
                this.CustomerId,
                this.Number
            ).GetValueOrDefault(base.GetHashCode());
        }
        #endregion
    }
}

ToDo: OrderService
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tact.Data.Entity;
using Tact.Models;

namespace Tact.Services
{
    /// <summary>
    /// オーダー サービスを提供します。
    /// </summary>
    public class OrderService : IOrderService, IService
    {
        #region Method
        /// <summary>
        /// 指定された主キー値を持つ値を検索します。
        /// </summary>
        /// <param name="id">ID。</param>
        /// <param name="user">ユーザー。</param>
        /// <returns>結果。</returns>
        public Order Find(string id, User user)
        {
            using (var context = new DatabaseContext(user))
            {
                var predicate = new Order { OfficeId = user.OfficeId, Id = id };

                return context.Orders
                    .Where(predicate)
                    .Include(entity => entity.Orderer)
                    .Include(entity => entity.Performed)
                    .SingleOrDefault();
            }
        }

        /// <summary>
        /// 指定された条件に基づいて値のシーケンスをフィルター処理します。
        /// </summary>
        /// <param name="user">ユーザー。</param>
        /// <param name="completed">完了済みかどうかを示す値。</param>
        /// <returns>結果。</returns>
        public IEnumerable<Order> Where(User user, bool completed = false)
        {
            using (var context = new DatabaseContext(user))
            {
                return context.Orders
                    .Where(entity =>
                        entity.OfficeId == user.OfficeId &&
                        ((!completed && (entity.Performed == null || entity.Performed.Date == null)) ||
                        (completed && (entity.Performed != null && entity.Performed.Date != null)))
                    )
                    .Include(entity => entity.Orderer)
                    .OrderByDescending(entity => entity.Id)
                    .ToList();
            }
        }

        /// <summary>
        /// 追加または更新します。
        /// </summary>
        /// <param name="value">値。</param>
        /// <param name="user">ユーザー。</param>
        public void AddOrUpdate(Order value, User user)
        {
            value.Refresh();

            using (var context = new DatabaseContext(user))
            {
                context.Orders.Merge(value);

                context.SaveChanges();
            }
        }

        /// <summary>
        /// 削除します。
        /// </summary>
        /// <param name="value">値。</param>
        /// <param name="user">ユーザー。</param>
        public void Remove(Order value, User user)
        {
            using (var context = new DatabaseContext(user))
            {
                context.Orders.Attach(value);
                context.Orders.Remove(value);

                context.SaveChanges();
            }
        }
        #endregion
    }
}

ToDo: PerformanceService
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tact.Data.Entity;
using Tact.Models;

namespace Tact.Services
{
    /// <summary>
    /// オーダー サービスを提供します。
    /// </summary>
    internal class PerformanceService : IPerformanceService, IService
    {
        #region Method
        /// <summary>
        /// 指定された主キー値を持つ値を検索します。
        /// </summary>
        /// <param name="id">ID。</param>
        /// <param name="user">ユーザー。</param>
        /// <returns>結果。</returns>
        public Order Find(string id, User user)
        {
            using (var context = new DatabaseContext(user))
            {
                var source = (
                    from order in context.Orders
                    join cost in (
                        from cost in context.Costs
                        group cost by new { cost.OfficeId, cost.OrderId } into groupings
                        select new {
                            OfficeId = groupings.Key.OfficeId,
                            Id = groupings.Key.OrderId,
                            Outsourcing = groupings.Where(value => value.Type == CostType.Outsourcing).Sum(value => value.Value),
                            Material = groupings.Where(value => value.Type == CostType.Material).Sum(value => value.Value),
                            Field = groupings.Where(value => value.Type == CostType.Field).Sum(value => value.Value),
                            Direct = groupings.Where(value => value.Type == CostType.Direct).Sum(value => value.Value),
                        }
                    ) on
                        new { OfficeId = order.OfficeId, Id = order.Id } equals
                        new { OfficeId = cost.OfficeId, Id = cost.Id } into costs
                    from cost in costs.DefaultIfEmpty()
                    join invoice in (
                        from invoice in (
                            from invoice in context.Invoices
                            join receipt in context.Receipts on
                                new { OfficeId = invoice.OfficeId, Id = invoice.Id } equals
                                new { OfficeId = receipt.OfficeId, Id = receipt.InvoiceId } into receipts
                            select new {
                                OfficeId = invoice.OfficeId,
                                OrderId = invoice.OrderId,
                                Invoiced = invoice.Value,
                                Receipted = receipts.Sum(value => value.Value)
                            }
                        )
                        group invoice by new { invoice.OfficeId, invoice.OrderId } into groupings
                        select new {
                            OfficeId = groupings.Key.OfficeId,
                            Id = groupings.Key.OrderId,
                            Invoiced = groupings.Sum(value => value.Invoiced),
                            Receipted = groupings.Sum(value => value.Receipted)
                        }
                    ) on
                        new { OfficeId = order.OfficeId, Id = order.Id } equals
                        new { OfficeId = invoice.OfficeId, Id = invoice.Id } into invoices
                    from invoice in invoices.DefaultIfEmpty()
                    where
                        order.OfficeId == user.OfficeId &&
                        order.Id == id
                    orderby order.Id descending
                    select new {
                        Order = order,
                        Cost = cost,
                        Invoice = invoice,
                    }
                )
                .AsEnumerable().Select(entity => new Order {
                    OfficeId = entity.Order.OfficeId,
                    Office = new Office {
                        Id = entity.Order.OfficeId,
                    },
                    Id = entity.Order.Id,
                    ProjectId = entity.Order.ProjectId,
                    UserId = entity.Order.UserId,
                    SalesUserId = entity.Order.SalesUserId,
                    Name = entity.Order.Name,
                    DesignOffice = entity.Order.DesignOffice,
                    OrdererId = entity.Order.OrdererId,
                    ContractorId = entity.Order.ContractorId,
                    ContractorName = entity.Order.ContractorName,
                    Address = entity.Order.Address,
                    PhoneNumber = entity.Order.PhoneNumber,
                    FaxNumber = entity.Order.FaxNumber,
                    FromDate = entity.Order.FromDate,
                    ToDate = entity.Order.ToDate,
                    Type = entity.Order.Type,
                    Use = entity.Order.Use,
                    QuotedValue = entity.Order.QuotedValue,
                    FixedValue = entity.Order.FixedValue,
                    Remarks = entity.Order.Remarks,
                    OutsourcingCost = (entity.Cost == null) ? null : entity.Cost.Outsourcing,
                    MaterialCost = (entity.Cost == null) ? null : entity.Cost.Material,
                    FieldCost = (entity.Cost == null) ? null : entity.Cost.Field,
                    DirectCost = (entity.Cost == null) ? null : entity.Cost.Direct,
                    InvoicedValue = (entity.Invoice == null) ? null : entity.Invoice.Invoiced,
                    ReceiptedValue = (entity.Invoice == null) ? null : entity.Invoice.Receipted,
                })
                .SingleOrDefault();

                source.Performed = context.Performances.Find(user.OfficeId, id);

                return source;
            }
        }

        /// <summary>
        /// 指定された条件に基づいて値のシーケンスをフィルター処理します。
        /// </summary>
        /// <param name="user">ユーザー。</param>
        /// <param name="completed">完了済みかどうかを示す値。</param>
        /// <returns>結果。</returns>
        public IEnumerable<Order> Where(User user, bool completed = false)
        {
            using (var context = new DatabaseContext(user))
            {
                return (
                    from order in context.Orders
                    join orderer in context.Customers on order.OrdererId equals orderer.Id
                    join performance in context.Performances on
                        new { OfficeId = order.OfficeId, Id = order.Id } equals
                        new { OfficeId = performance.OfficeId, Id = performance.OrderId } into performances
                    from performed in performances.DefaultIfEmpty()
                    join cost in (
                        from cost in context.Costs
                        group cost by new { cost.OfficeId, cost.OrderId } into groupings
                        select new {
                            OfficeId = groupings.Key.OfficeId,
                            Id = groupings.Key.OrderId,
                            Outsourcing = groupings.Where(value => value.Type == CostType.Outsourcing).Sum(value => value.Value),
                            Material = groupings.Where(value => value.Type == CostType.Material).Sum(value => value.Value),
                            Field = groupings.Where(value => value.Type == CostType.Field).Sum(value => value.Value),
                            Direct = groupings.Where(value => value.Type == CostType.Direct).Sum(value => value.Value),
                        }
                    ) on
                        new { OfficeId = order.OfficeId, Id = order.Id } equals
                        new { OfficeId = cost.OfficeId, Id = cost.Id } into costs
                    from cost in costs.DefaultIfEmpty()
                    join invoice in (
                        from invoice in (
                            from invoice in context.Invoices
                            join receipt in context.Receipts on
                                new { OfficeId = invoice.OfficeId, Id = invoice.Id } equals
                                new { OfficeId = receipt.OfficeId, Id = receipt.InvoiceId } into receipts
                            select new {
                                OfficeId = invoice.OfficeId,
                                OrderId = invoice.OrderId,
                                Invoiced = invoice.Value,
                                Receipted = receipts.Sum(value => value.Value)
                            }
                        )
                        group invoice by new { invoice.OfficeId, invoice.OrderId } into groupings
                        select new {
                            OfficeId = groupings.Key.OfficeId,
                            Id = groupings.Key.OrderId,
                            Invoiced = groupings.Sum(value => value.Invoiced),
                            Receipted = groupings.Sum(value => value.Receipted)
                        }
                    ) on
                        new { OfficeId = order.OfficeId, Id = order.Id } equals
                        new { OfficeId = invoice.OfficeId, Id = invoice.Id } into invoices
                    from invoice in invoices.DefaultIfEmpty()
                    where
                        order.OfficeId == user.OfficeId &&
                        ((!completed && (performed == null || performed.Date == null)) ||
                        (completed && (performed != null && performed.Date != null)))
                    orderby order.Id descending
                    select new {
                        Order = order,
                        Orderer = orderer,
                        Performed = performed,
                        Cost = cost,
                        Invoice = invoice,
                    }
                )
                .AsEnumerable().Select(entity => new Order {
                    OfficeId = entity.Order.OfficeId,
                    Office = new Office {
                        Id = entity.Order.OfficeId,
                    },
                    Id = entity.Order.Id,
                    ProjectId = entity.Order.ProjectId,
                    UserId = entity.Order.UserId,
                    SalesUserId = entity.Order.SalesUserId,
                    Name = entity.Order.Name,
                    DesignOffice = entity.Order.DesignOffice,
                    OrdererId = entity.Order.OrdererId,
                    Orderer = new Customer {
                        Id = entity.Orderer.Id,
                        Name = entity.Orderer.Name
                    },
                    ContractorId = entity.Order.ContractorId,
                    ContractorName = entity.Order.ContractorName,
                    Address = entity.Order.Address,
                    PhoneNumber = entity.Order.PhoneNumber,
                    FaxNumber = entity.Order.FaxNumber,
                    FromDate = entity.Order.FromDate,
                    ToDate = entity.Order.ToDate,
                    Type = entity.Order.Type,
                    Use = entity.Order.Use,
                    QuotedValue = entity.Order.QuotedValue,
                    FixedValue = entity.Order.FixedValue,
                    Remarks = entity.Order.Remarks,
                    Performed = (entity.Performed == null) ? null : new Performance {
                        OfficeId = entity.Performed.OfficeId,
                        OrderId = entity.Performed.OrderId,
                        Date = entity.Performed.Date,
                        Value = entity.Performed.Value,
                        Remarks = entity.Performed.Remarks,
                    },
                    OutsourcingCost = (entity.Cost == null) ? null : entity.Cost.Outsourcing,
                    MaterialCost = (entity.Cost == null) ? null : entity.Cost.Material,
                    FieldCost = (entity.Cost == null) ? null : entity.Cost.Field,
                    DirectCost = (entity.Cost == null) ? null : entity.Cost.Direct,
                    InvoicedValue = (entity.Invoice == null) ? null : entity.Invoice.Invoiced,
                    ReceiptedValue = (entity.Invoice == null) ? null : entity.Invoice.Receipted,
                })
                .ToList();
            }
        }

        /// <summary>
        /// 追加または更新します。
        /// </summary>
        /// <param name="value">値。</param>
        /// <param name="user">ユーザー。</param>
        public void AddOrUpdate(Order value, User user)
        {
            value.Refresh();

            using (var context = new DatabaseContext(user))
            {
                context.Performances.Merge(value.Performed);

                context.SaveChanges();
            }
        }
        #endregion
    }
}
ToDo: ReceiptService

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tact.Data.Entity;
using Tact.Models;

namespace Tact.Services
{
    /// <summary>
    /// 受領 サービスを提供します。
    /// </summary>
    internal class ReceiptService : IReceiptService, IService
    {
        #region Method
        /// <summary>
        /// ユーザーのコレクションを取得します。
        /// </summary>
        /// <param name="user">ユーザー。</param>
        /// <returns>結果。</returns>
        public List<User> Users(User user)
        {
            return this.Orders()
                .Where(entity => entity.OfficeId == user.OfficeId)
                .Select(entity => entity.User).Distinct()
                .OrderBy(entity => entity.Id)
                .ToList();
        }

        /// <summary>
        /// オーダーのコレクションを取得します。
        /// </summary>
        /// <param name="user">ユーザー。</param>
        /// <returns>結果。</returns>
        public List<Order> Orders(User user)
        {
            if (user == null) return new List<Order>();

            var source = this.Orders()
                .Where(entity =>
                    entity.OfficeId == user.OfficeId &&
                    entity.UserId == user.Id
                )
                .OrderByDescending(entity => entity.Id)
                .ToList();

            source.Insert(0, new Order());

            return source;
        }

        /// <summary>
        /// 請求のコレクションを取得します。
        /// </summary>
        /// <param name="order">オーダー。</param>
        /// <param name="user">ユーザー。</param>
        /// <returns>結果。</returns>
        public List<Invoice> Invoices(Order order, User user)
        {
            if (order == null || user == null) return new List<Invoice>();

            using (var context = new DatabaseContext())
            {
                return context.Invoices
                    .Where(entity =>
                        entity.OfficeId == user.OfficeId &&
                        entity.OrderId == order.Id
                    )
                    .Include(entity => entity.Order)
                    .OrderBy(entity => entity.Id)
                    .ToList();
            }
        }

        /// <summary>
        /// オーダーのコレクションを取得します。
        /// </summary>
        /// <param name="user">ユーザー。</param>
        /// <returns>結果。</returns>
        private List<Order> Orders()
        {
            using (var context = new DatabaseContext())
            {
                return (
                    from source in (
                        from source in (
                            from invoice in context.Invoices
                            join receipt in context.Receipts on
                                new { OfficeId = invoice.OfficeId, Id = invoice.Id } equals
                                new { OfficeId = receipt.OfficeId, Id = receipt.InvoiceId } into receipts
                            select new {
                                OfficeId = invoice.OfficeId,
                                OrderId = invoice.OrderId,
                                Invoiced = invoice.Value,
                                Receipted = receipts.Sum(value => value.Value)
                            }
                        )
                        group source by new { source.OfficeId, source.OrderId } into groupings
                        select new {
                            OfficeId = groupings.Key.OfficeId,
                            Id = groupings.Key.OrderId,
                            Invoiced = groupings.Sum(value => value.Invoiced),
                            Receipted = groupings.Sum(value => value.Receipted)
                        }
                    )
                    join order in context.Orders on
                        new { OfficeId = source.OfficeId, Id = source.Id } equals
                        new { OfficeId = order.OfficeId, Id = order.Id }
                    join user in context.Users on order.UserId equals user.Id
                    join orderer in context.Customers on order.OrdererId equals orderer.Id
                    join performance in context.Performances on
                        new { OfficeId = order.OfficeId, Id = order.Id } equals
                        new { OfficeId = performance.OfficeId, Id = performance.OrderId } into performances
                    from performed in performances.DefaultIfEmpty()
                    where
                        (source.Invoiced != source.Receipted) ||
                        (performed == null || performed.Date == null)
                    select new {
                        OfficeId = order.OfficeId,
                        Id = order.Id,
                        Name = order.Name,
                        User = new {
                            Id = user.Id,
                            Name = user.Name
                        },
                        Orderer = new {
                            Id = orderer.Id,
                            Name = orderer.Name
                        },
                        FixedValue = order.FixedValue,
                        Performed = new {
                            Date = performed.Date,
                            Value = performed.Value,
                            Remarks = performed.Remarks,
                        },
                        Invoiced = source.Invoiced,
                        Receipted = source.Receipted,
                    }
                )
                .AsEnumerable().Select(entity => new Order {
                    OfficeId = entity.OfficeId,
                    Office = new Office {
                        Id = entity.OfficeId,
                    },
                    Id = entity.Id,
                    Name = entity.Name,
                    UserId = entity.User.Id,
                    User = new User {
                        Id = entity.User.Id,
                        Name = entity.User.Name,
                        OfficeId = entity.OfficeId,
                        Office = new Office {
                            Id = entity.OfficeId,
                        }
                    },
                    OrdererId = entity.Orderer.Id,
                    Orderer = new Customer {
                        Id = entity.Orderer.Id,
                        Name = entity.Orderer.Name,
                        OfficeId = entity.OfficeId,
                        Office = new Office {
                            Id = entity.OfficeId,
                        }
                    },
                    FixedValue = entity.FixedValue,
                    Performed = new Performance {
                        OfficeId = entity.OfficeId,
                        OrderId = entity.Id,
                        Date = entity.Performed.Date,
                        Value = entity.Performed.Value,
                        Remarks = entity.Performed.Remarks,
                    },
                    InvoicedValue = entity.Invoiced,
                    ReceiptedValue = entity.Receipted,
                })
                .ToList();
            }
        }

        /// <summary>
        /// 指定された条件に基づいて値のシーケンスをフィルター処理します。
        /// </summary>
        /// <param name="user">ユーザー。</param>
        /// <returns>結果。</returns>
        public IEnumerable<Receipt> Where(User user)
        {
            if (user == null) return new List<Receipt>();

            var orders = this.Orders(user);

            using (var context = new DatabaseContext(user))
            {
                return context.Receipts
                    .Where(entity =>
                        entity.OfficeId == user.OfficeId &&
                        entity.Invoice.Order.UserId == user.Id
                    )
                    .Include(entity => entity.Invoice)
                    .Include(entity => entity.Invoice.Order)
                    .ToList()
                    .Where(entity => orders.Contains(entity.Invoice.Order))
                    .OrderBy(entity => entity.InvoiceId)
                    .ThenBy(entity => entity.Number)
                    .ToList();
            }
        }

        /// <summary>
        /// 変更を保存します。
        /// </summary>
        /// <param name="values">値のコレクション。</param>
        /// <param name="user">ユーザー。</param>
        public void SaveChanges(IEnumerable<Receipt> values, User user)
        {
            values.ForEach(value => value.Refresh());

            var orders = this.Orders(user);

            using (var context = new DatabaseContext(user))
            {
                var source = context.Receipts
                    .Where(entity =>
                        entity.OfficeId == user.OfficeId &&
                        entity.Invoice.Order.UserId == user.Id
                    )
                    .Include(entity => entity.Invoice)
                    .Include(entity => entity.Invoice.Order)
                    .ToList()
                    .Where(entity => orders.Contains(entity.Invoice.Order))
                    .ToList();

                context.Receipts.Merge(source, values);

                context.SaveChanges();
            }
        }
        #endregion
    }
}

ToDo: DeductionService
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tact.Data.Entity;
using Tact.Models;

namespace Tact.Services
{
    /// <summary>
    /// 控除 サービスを提供します。
    /// </summary>
    internal class DeductionService : IDeductionService, IService
    {
        #region Constructor
        /// <summary>
        /// 新しいインスタンスを初期化します。
        /// </summary>
        public DeductionService()
        {
            this.Types = new List<CustomerType> {
                CustomerType.Painting,
                CustomerType.Outsourcee,
            };
        }
        #endregion

        #region Property
        /// <summary>
        /// タイプのコレクションを取得します。
        /// </summary>
        public IEnumerable<CustomerType> Types { get; private set; }
        #endregion

        #region Method
        /// <summary>
        /// 取引先のコレクションを取得します。
        /// </summary>
        /// <param name="date">年月。</param>
        /// <param name="user">ユーザー。</param>
        /// <returns>結果。</returns>
        public List<Customer> Customers(string date, User user)
        {
            using (var context = new DatabaseContext())
            {
                return context.Costs
                    .Where(entity =>
                        entity.OfficeId == user.OfficeId &&
                        entity.YearMonth == date &&
                        this.Types.Contains(entity.Customer.Type)
                    )
                    .Select(entity => entity.Customer).Distinct()
                    .OrderBy(entity => entity.Id)
                    .ToList();
            }
        }

        /// <summary>
        /// コストのコレクションを取得します。
        /// </summary>
        /// <param name="date">年月。</param>
        /// <param name="customer">取引先。</param>
        /// <param name="user">ユーザー。</param>
        /// <returns>結果。</returns>
        public IEnumerable<Cost> Costs(string date, Customer customer, User user)
        {
            if (customer == null || user == null) return new List<Cost>();

            using (var context = new DatabaseContext(user))
            {
                return context.Costs
                    .Where(entity =>
                        entity.OfficeId == user.OfficeId &&
                        entity.YearMonth == date &&
                        entity.CustomerId == customer.Id &&
                        this.Types.Contains(entity.Customer.Type)
                    )
                    .Include(entity => entity.Order)
                    .OrderBy(entity => entity.OrderId)
                    .ThenBy(entity => entity.Number)
                    .ToList();
            }
        }

        /// <summary>
        /// 指定された条件に基づいて値のシーケンスをフィルター処理します。
        /// </summary>
        /// <param name="date">年月。</param>
        /// <param name="id">ID。</param>
        /// <param name="user">ユーザー。</param>
        /// <returns>結果。</returns>
        public IEnumerable<Deduction> Where(string date, string id, User user)
        {
            using (var context = new DatabaseContext(user))
            {
                var source = context.Deductions
                    .Where(entity =>
                        entity.OfficeId == user.OfficeId &&
                        entity.YearMonth == date &&
                        entity.CustomerId == id &&
                        entity.Number != (int)DeductionNumber.Empty
                    )
                    .OrderBy(entity => entity.Number)
                    .ToList();

                return source;
            }
        }

        /// <summary>
        /// 変更を保存します。
        /// </summary>
        /// <param name="date">年月。</param>
        /// <param name="id">ID。</param>
        /// <param name="values">値のコレクション。</param>
        /// <param name="user">ユーザー。</param>
        public void SaveChanges(string date, string id, IEnumerable<Deduction> values, User user)
        {
            var source = values.ToList();

            if (!values.Any(value => value.Number == (int)DeductionNumber.Empty))
            {
                source.Add(new Deduction {
                    OfficeId = user.OfficeId,
                    YearMonth = date,
                    CustomerId = id,
                    Number = (int)DeductionNumber.Empty
                });
            }

            source = source.Where(entity => entity.Number < (int)DeductionNumber.Membership).ToList();

            source.ForEach(value => value.Refresh());

            using (var context = new DatabaseContext(user))
            {
                context.Deductions
                    .Where(entity =>
                        entity.OfficeId == user.OfficeId &&
                        entity.YearMonth == date &&
                        entity.CustomerId == id
                    )
                    .Load();

                context.Deductions.Merge(source);

                context.SaveChanges();
            }
        }
        #endregion
    }
}
ToDo: IPerformanceService
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tact.Models;

namespace Tact.Services
{
    /// <summary>
    /// オーダー サービスを提供します。
    /// </summary>
    public interface IPerformanceService
    {
        #region Method
        /// <summary>
        /// 指定された主キー値を持つ値を検索します。
        /// </summary>
        /// <param name="id">ID。</param>
        /// <param name="user">ユーザー。</param>
        /// <returns>結果。</returns>
        Order Find(string id, User user);

        /// <summary>
        /// 指定された条件に基づいて値のシーケンスをフィルター処理します。
        /// </summary>
        /// <param name="user">ユーザー。</param>
        /// <param name="completed">完了済みかどうかを示す値。</param>
        /// <returns>結果。</returns>
        IEnumerable<Order> Where(User user, bool completed = false);

        /// <summary>
        /// 追加または更新します。
        /// </summary>
        /// <param name="value">値。</param>
        /// <param name="user">ユーザー。</param>
        void AddOrUpdate(Order value, User user);
        #endregion
    }
}
ToDo: IOrderService
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tact.Models;

namespace Tact.Services
{
    /// <summary>
    /// オーダー サービスを提供します。
    /// </summary>
    public interface IOrderService
    {
        #region Method
        /// <summary>
        /// 指定された主キー値を持つ値を検索します。
        /// </summary>
        /// <param name="id">ID。</param>
        /// <param name="user">ユーザー。</param>
        /// <returns>結果。</returns>
        Order Find(string id, User user);

        /// <summary>
        /// 指定された条件に基づいて値のシーケンスをフィルター処理します。
        /// </summary>
        /// <param name="user">ユーザー。</param>
        /// <param name="completed">完了済みかどうかを示す値。</param>
        /// <returns>結果。</returns>
        IEnumerable<Order> Where(User user, bool completed = false);

        /// <summary>
        /// 追加または更新します。
        /// </summary>
        /// <param name="value">値。</param>
        /// <param name="user">ユーザー。</param>
        void AddOrUpdate(Order value, User user);

        /// <summary>
        /// 削除します。
        /// </summary>
        /// <param name="value">値。</param>
        /// <param name="user">ユーザー。</param>
        void Remove(Order value, User user);
        #endregion
    }
}
ToDo: IDeductionService
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tact.Models;

namespace Tact.Services
{
    /// <summary>
    /// 控除 サービスを提供します。
    /// </summary>
    public interface IDeductionService
    {
        #region Property
        /// <summary>
        /// タイプのコレクションを取得します。
        /// </summary>
        IEnumerable<CustomerType> Types { get; }
        #endregion

        #region Method
        /// <summary>
        /// 取引先のコレクションを取得します。
        /// </summary>
        /// <param name="date">年月。</param>
        /// <param name="user">ユーザー。</param>
        /// <returns>結果。</returns>
        List<Customer> Customers(string date, User user);

        /// <summary>
        /// コストのコレクションを取得します。
        /// </summary>
        /// <param name="date">年月。</param>
        /// <param name="customer">取引先。</param>
        /// <param name="user">ユーザー。</param>
        /// <returns>結果。</returns>
        IEnumerable<Cost> Costs(string date, Customer customer, User user);

        /// <summary>
        /// 指定された条件に基づいて値のシーケンスをフィルター処理します。
        /// </summary>
        /// <param name="date">年月。</param>
        /// <param name="id">ID。</param>
        /// <param name="user">ユーザー。</param>
        /// <returns>結果。</returns>
        IEnumerable<Deduction> Where(string date, string id, User user);

        /// <summary>
        /// 変更を保存します。
        /// </summary>
        /// <param name="date">年月。</param>
        /// <param name="id">ID。</param>
        /// <param name="values">値のコレクション。</param>
        /// <param name="user">ユーザー。</param>
        void SaveChanges(string date, string id, IEnumerable<Deduction> values, User user);
        #endregion
    }
}
ToDo: Cost
using Prism.Commands;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tact.Windows.Mvvm;
using Tact.Windows.Resources;

namespace Tact.Windows.ViewModels
{
    /// <summary>
    /// コスト ビューモデルを提供します。
    /// </summary>
    public class Cost : Bindable<Models.Cost>
    {
        #region Constructor
        /// <summary>
        /// 新しいインスタンスを初期化します。
        /// </summary>
        public Cost()
            : this(new Models.Cost())
        {
        }

        /// <summary>
        /// 新しいインスタンスを初期化します。
        /// </summary>
        /// <param name="source">ソース。</param>
        public Cost(Models.Cost source)
            : base(source)
        {
            this.RegisterRelation("Prepaid", "Total");
            this.RegisterRelation("Value", "Total");
        }
        #endregion

        #region Property
        /// <summary>
        /// オフィスを取得または設定します。
        /// </summary
        [Display(Name = "拠点")]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Messages))]
        public Office Office
        {
            get { return this.GetProperty<Office>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// オーダーを取得または設定します。
        /// </summary
        [Display(Name = "工事")]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Messages))]
        public Models.Order Order
        {
            get { return this.GetProperty<Models.Order>(); }
            set { if (value == null) return; this.SetProperty(value); this.OrderId = (value == null) ? null : value.Id; }
        }

        /// <summary>
        /// オーダーIDを取得または設定します。
        /// </summary>
        [Display(Name = "工事番号")]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Messages))]
        [MaxLength(6, ErrorMessageResourceName = "MaxLength", ErrorMessageResourceType = typeof(Messages))]
        public string OrderId
        {
            get { return this.GetProperty<string>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 年月を取得または設定します。
        /// </summary>
        [Display(Name = "年月")]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Messages))]
        [MaxLength(6, ErrorMessageResourceName = "MaxLength", ErrorMessageResourceType = typeof(Messages))]
        public string YearMonth
        {
            get { return this.GetProperty<string>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 取引先を取得または設定します。
        /// </summary
        [Display(Name = "支払先")]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Messages))]
        public Customer Customer
        {
            get { return this.GetProperty<Customer>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 取引先IDを取得または設定します。
        /// </summary>
        [Display(Name = "支払先")]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Messages))]
        [MaxLength(6, ErrorMessageResourceName = "MaxLength", ErrorMessageResourceType = typeof(Messages))]
        public string CustomerId
        {
            get { return this.GetProperty<string>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// ナンバーを取得または設定します。
        /// </summary>
        [Display(Name = "番号")]
        public int Number
        {
            get { return this.GetProperty<int>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 取極額を取得または設定します。
        /// </summary>
        [Display(Name = "取極金額")]
        public double? Agreement
        {
            get { return this.GetProperty<double?>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 既払額を取得または設定します。
        /// </summary>
        [Display(Name = "既支払額")]
        public double? Prepaid
        {
            get { return this.GetProperty<double?>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 値を取得または設定します。
        /// </summary>
        [Display(Name = "当月支払額")]
        public double? Value
        {
            get { return this.GetProperty<double?>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 合計を取得します。
        /// </summary>
        [Display(Name = "支払額合計")]
        public double? Total
        {
            get { return this.Prepaid.GetValueOrDefault() + this.Value.GetValueOrDefault(); }
        }
        #endregion

        #region Method
        /// <summary>
        /// コミットします。
        /// </summary>
        /// <returns>結果。</returns>
        public override Models.Cost Commit()
        {
            this.Source.OfficeId = this.Office.Id;
            this.Source.OrderId = this.OrderId;
            this.Source.YearMonth = this.YearMonth;
            this.Source.CustomerId = this.CustomerId;
            this.Source.Number = this.Number;
            this.Source.Agreement = this.Agreement;
            this.Source.Value = this.Value;

            return this.Source;
        }

        /// <summary>
        /// ロールバックします。
        /// </summary>
        public override void Rollback()
        {
            this.Office = this.Source.Office.Bindable<Office>();
            this.Office.Id = this.Source.OfficeId;
            this.Order = this.Source.Order;
            this.OrderId = this.Source.OrderId;
            this.YearMonth = this.Source.YearMonth;
            this.Customer = this.Source.Customer.Bindable<Customer>();
            this.CustomerId = this.Source.CustomerId;
            this.Number = this.Source.Number;
            this.Agreement = this.Source.Agreement;
            this.Prepaid = this.Source.Prepaid;
            this.Value = this.Source.Value;
        }
        #endregion
    }
}
ToDo: Deduction
using Prism.Commands;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tact.Windows.Mvvm;
using Tact.Windows.Resources;

namespace Tact.Windows.ViewModels
{
    /// <summary>
    /// 控除 ビューモデルを提供します。
    /// </summary>
    public class Deduction : Bindable<Models.Deduction>
    {
        #region Constructor
        /// <summary>
        /// 新しいインスタンスを初期化します。
        /// </summary>
        public Deduction()
            : this(new Models.Deduction())
        {
        }

        /// <summary>
        /// 新しいインスタンスを初期化します。
        /// </summary>
        /// <param name="source">ソース。</param>
        public Deduction(Models.Deduction source)
            : base(source)
        {
            this.RegisterRelation("Number", "Required");
        }
        #endregion

        #region Property
        /// <summary>
        /// オフィスを取得または設定します。
        /// </summary
        [Display(Name = "拠点")]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Messages))]
        public Office Office
        {
            get { return this.GetProperty<Office>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 年月を取得または設定します。
        /// </summary>
        [Display(Name = "年月")]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Messages))]
        [MaxLength(6, ErrorMessageResourceName = "MaxLength", ErrorMessageResourceType = typeof(Messages))]
        public string YearMonth
        {
            get { return this.GetProperty<string>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 取引先を取得または設定します。
        /// </summary
        [Display(Name = "支払先")]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Messages))]
        public Customer Customer
        {
            get { return this.GetProperty<Customer>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 取引先IDを取得または設定します。
        /// </summary>
        [Display(Name = "支払先")]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Messages))]
        [MaxLength(6, ErrorMessageResourceName = "MaxLength", ErrorMessageResourceType = typeof(Messages))]
        public string CustomerId
        {
            get { return this.GetProperty<string>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// ナンバーを取得または設定します。
        /// </summary>
        [Display(Name = "番号")]
        public int Number
        {
            get { return this.GetProperty<int>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 名称を取得または設定します。
        /// </summary>
        [Display(Name = "内容")]
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Messages))]
        [MaxLength(64, ErrorMessageResourceName = "MaxLength", ErrorMessageResourceType = typeof(Messages))]
        public string Name
        {
            get { return this.GetProperty<string>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 必須かどうかを示す値を取得します。
        /// </summary>
        public bool Required
        {
            get { return (int)DeductionNumber.Empty <= this.Number; }
        }

        /// <summary>
        /// 値を取得または設定します。
        /// </summary>
        [Display(Name = "金額")]
        public double? Value
        {
            get { return this.GetProperty<double?>(); }
            set { this.SetProperty(value); }
        }
        #endregion

        #region Method
        /// <summary>
        /// コミットします。
        /// </summary>
        /// <returns>結果。</returns>
        public override Models.Deduction Commit()
        {
            this.Source.OfficeId = this.Office.Id;
            this.Source.YearMonth = this.YearMonth;
            this.Source.CustomerId = this.CustomerId;
            this.Source.Number = this.Number;
            this.Source.Name = this.Name;
            this.Source.Value = this.Value;

            return this.Source;
        }

        /// <summary>
        /// ロールバックします。
        /// </summary>
        public override void Rollback()
        {
            this.Office = this.Source.Office.Bindable<Office>();
            this.Office.Id = this.Source.OfficeId;
            this.YearMonth = this.Source.YearMonth;
            this.Customer = this.Source.Customer.Bindable<Customer>();
            this.CustomerId = this.Source.CustomerId;
            this.Number = this.Source.Number;
            this.Name = this.Source.Name;
            this.Value = this.Source.Value;
        }
        #endregion
    }
}
ToDo: BindableCollection
using Microsoft.Practices.Unity;
using Prism.Commands;
using Prism.Events;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
using Tact.Exceptions;
using Tact.Windows.Commands;
using Tact.Windows.Events;
using Tact.Windows.Interactivity;
using Tact.Windows.Resources;

namespace Tact.Windows.Mvvm
{
    /// <summary>
    /// コレクション管理に共通のバインド機能を提供します。
    /// </summary>
    /// <typeparam name="TBindable">バインドの型。</typeparam>
    /// <typeparam name="TSource">ソースの型。</typeparam>
    public abstract class BindableCollection<TBindable, TSource> : Bindable
        where TBindable : Bindable<TSource>, new()
        where TSource : Record, IEquatable<TSource>, new()
    {
        #region Constructor
        /// <summary>
        /// 新しいインスタンスを初期化します。
        /// </summary>
        public BindableCollection()
        {
            this.Cache = new Dictionary<TSource, TBindable>();

            this.Mode = CommitMode.Single;
            this.Source = new ListCollectionView(new List<TSource>());

            this.Commands = new CollectionCommands {
                Refresh = new DelegateCommand(this.Refresh, this.CanRefresh),
                Add = new DelegateCommand(this.Add, this.CanAdd),
                Edit = new DelegateCommand(this.Edit, this.CanEdit),
                Remove = new DelegateCommand(this.Remove, this.CanRemove),
                Commit = new DelegateCommand(this.Commit, this.CanCommit),
                Rollback = new DelegateCommand(this.Rollback, this.CanRollback),
                Print = new DelegateCommand(this.Print, this.CanPrint),
            };

            this.RegisterRelation("Current", this.Commands.ToArray());
            this.RegisterRelation("IsEditing", "IsReadOnly");
            this.RegisterRelation("IsEditing", this.Commands.ToArray());
        }
        #endregion

        #region Property
        /// <summary>
        /// モードを取得します。
        /// </summary>
        public CommitMode Mode
        {
            get { return this.GetProperty<CommitMode>(); }
            protected set { this.SetProperty(value); }
        }

        /// <summary>
        /// ソースのビューを取得します。
        /// </summary>
        public ListCollectionView Source
        {
            get { return this.GetProperty<ListCollectionView>(); }
            private set { this.SetProperty(value); this.Cache.Clear(); }
        }

        /// <summary>
        /// キャッシュを取得または設定します。
        /// </summary>
        private Dictionary<TSource, TBindable> Cache { get; set; }

        /// <summary>
        /// カレントを取得または設定します。
        /// </summary>
        public TBindable Current
        {
            get { return this.GetProperty<TBindable>(); }
            private set
            {
                if (this.Current != null) this.Current.PropertyChanged -= this.OnCurrentPropertyChanged;

                this.SetProperty(value);
                this.CurrentSource = (value == null) ? null : value.Source;

                if (this.Current != null) this.Current.PropertyChanged += this.OnCurrentPropertyChanged;
            }
        }

        /// <summary>
        /// カレントソースを取得または設定します。
        /// </summary>
        public TSource CurrentSource { get; private set; }

        /// <summary>
        /// 編集モードであるかどうかを示す値を取得または設定します。
        /// </summary>
        public bool IsEditing
        {
            get { return this.GetProperty<bool>(); }
            private set { if (this.SetProperty(value)) this.EventAggregator.GetEvent<EditingChanged>().Publish(value); }
        }

        /// <summary>
        /// 編集モードであるかどうかを示す値を取得します。
        /// </summary>
        public bool IsReadOnly
        {
            get { return !this.IsEditing; }
        }

        /// <summary>
        /// コマンドを取得します。
        /// </summary>
        public CollectionCommands Commands { get; private set; }

        /// <summary>
        /// イベント アグリゲーターを取得または設定します。
        /// </summary>
        [Dependency]
        public IEventAggregator EventAggregator { get; set; }
        #endregion

        #region Method

        #region Activate
        /// <summary>
        /// 活性化するときに発生します。
        /// </summary>
        /// <param name="context">コンテキスト。</param>
        protected override void OnActivate(NavigationContext context)
        {
            base.OnActivate(context);

            CollectionCompositeCommands.RegisterCommand(this.Commands);

            this.IsEditing = false;
            this.EventAggregator.GetEvent<EditingChanged>().Publish(this.IsEditing);

            this.Refresh();

            this.Source.MoveCurrentToFirst();
        }

        /// <summary>
        /// 非活性化するときに発生します。
        /// </summary>
        /// <param name="context">コンテキスト。</param>
        protected override void OnDeactivate(NavigationContext context)
        {
            if (this.Source != null) this.Source.CurrentChanging -= this.OnCurrentChanging;
            if (this.Source != null) this.Source.CurrentChanged -= this.OnCurrentChanged;
            if (this.Current != null) this.Current.PropertyChanged -= this.OnCurrentPropertyChanged;

            this.Rollback();

            CollectionCompositeCommands.UnregisterCommand(this.Commands);

            base.OnDeactivate(context);
        }
        #endregion

        #region Refresh
        /// <summary>
        /// 更新 コマンドが実行可能かどうかを判断します。
        /// </summary>
        /// <returns>コマンドを実行できるかどうかを示す値。</returns>
        protected virtual bool CanRefresh() { return true; }

        /// <summary>
        /// 更新 コマンドを実行します。
        /// </summary>
        protected virtual void Refresh()
        {
            if (!this.Rollback(this.IsEditing)) return;

            if (this.Mode == CommitMode.Single)
            {
                var source = this.Where().ToList();

                var current = source.FirstOrDefault(value => value.Equals((this.Current == null) ? null : this.Current.Source));

                this.Source.CurrentChanging -= this.OnCurrentChanging;
                this.Source.CurrentChanged -= this.OnCurrentChanged;

                this.Source = new ListCollectionView(source);
                this.Source.MoveCurrentTo(null);
                this.Current = null;

                this.Source.CurrentChanging += this.OnCurrentChanging;
                this.Source.CurrentChanged += this.OnCurrentChanged;

                this.Source.MoveCurrentTo(current);
            }
            else if (this.Mode == CommitMode.Multiple)
            {
                var source = this.Where().ToList().Bindable<TBindable>();

                var current = source.FirstOrDefault(value => value.Source.Equals((this.Current == null) ? null : this.Current.Source));

                this.Source.CurrentChanging -= this.OnCurrentChanging;
                this.Source.CurrentChanged -= this.OnCurrentChanged;

                this.Source = new ListCollectionView(source);
                this.Source.MoveCurrentTo(null);
                this.Current = null;

                this.Source.CurrentChanging += this.OnCurrentChanging;
                this.Source.CurrentChanged += this.OnCurrentChanged;

                this.Source.MoveCurrentTo(current);
            }
        }

        /// <summary>
        /// 値のシーケンスをフィルター処理します。
        /// </summary>
        /// <returns>結果。</returns>
        protected abstract IEnumerable<TSource> Where();

        /// <summary>
        /// カレントを検索します。
        /// </summary>
        /// <returns>結果。</returns>
        protected abstract TSource Find();
        #endregion

        #region Current
        /// <summary>
        /// カレントが変更される前にこのイベントが発生します。
        /// </summary>
        /// <param name="sender">イベントのソース。</param>
        /// <param name="e">イベントデータ。</param>
        private void OnCurrentChanging(object sender, CurrentChangingEventArgs e)
        {
            if (this.Mode == CommitMode.Single && !this.Rollback(this.IsEditing)) e.Cancel = true;
        }

        /// <summary>
        /// カレントが変更された後にこのイベントが発生します。
        /// </summary>
        /// <param name="sender">イベントのソース。</param>
        /// <param name="e">イベントデータ。</param>
        private void OnCurrentChanged(object sender, EventArgs e)
        {
            this.CurrentBind();
        }

        /// <summary>
        /// カレントのプロパティ値が変更されたときに発生します。
        /// </summary>
        /// <param name="sender">イベントのソース。</param>
        /// <param name="e">イベントデータ。</param>
        protected virtual void OnCurrentPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            this.RaiseCanExecuteChanged(this.Commands.Commit);
        }

        /// <summary>
        /// カレントをバインドします。
        /// </summary>
        private void CurrentBind()
        {
            this.CurrentBind(this.Source.CurrentItem);
        }

        /// <summary>
        /// カレントをバインドします。
        /// </summary>
        protected void CurrentBind(object source)
        {
            var current = source as TBindable;

            if (source is TSource)
            {
                var key = source as TSource;

                if (!this.Cache.ContainsKey(key)) this.Cache.Add(key, key.Bindable<TBindable>());

                current = this.Cache[key];
            }

            if (current != null && current.LoadState == Models.LoadState.Incomplete)
            {
                this.CurrentSource = current.Source;

                current.Source = this.Find();
            }

            this.Current = current;
        }
        #endregion

        #region Edit
        /// <summary>
        /// 編集 コマンドが実行可能かどうかを判断します。
        /// </summary>
        /// <returns>コマンドを実行できるかどうかを示す値。</returns>
        protected virtual bool CanEdit() { return !this.IsEditing && (this.Mode == CommitMode.Multiple || this.Current != null); }

        /// <summary>
        /// 編集 コマンドを実行します。
        /// </summary>
        protected virtual void Edit()
        {
            if (this.Mode == CommitMode.Single) this.Current.Source = this.Find();
            else if (this.Mode == CommitMode.Multiple) this.Refresh();

            this.IsEditing = true;
        }
        #endregion

        #region Add
        /// <summary>
        /// 追加 コマンドが実行可能かどうかを判断します。
        /// </summary>
        /// <returns>コマンドを実行できるかどうかを示す値。</returns>
        protected virtual bool CanAdd()
        {
            return
                (this.Mode == CommitMode.Single && !this.IsEditing) ||
                (this.Mode == CommitMode.Multiple && this.IsEditing);
        }

        /// <summary>
        /// 追加 コマンドを実行します。
        /// </summary>
        protected virtual void Add()
        {
            if (this.Mode == CommitMode.Single)
            {
                if (!this.Rollback(this.IsEditing)) return;

                this.Current = this.Create();
            }
            else if (this.Mode == CommitMode.Multiple)
            {
                this.Source.AddNewItem(this.Create());
                this.Source.CommitNew();
                this.Source.Refresh();
            }

            this.IsEditing = true;
        }

        /// <summary>
        /// 生成します。
        /// </summary>
        /// <returns>結果。</returns>
        protected virtual TBindable Create() { return new TBindable(); }
        #endregion

        #region Remove
        /// <summary>
        /// 削除 コマンドが実行可能かどうかを判断します。
        /// </summary>
        /// <returns>コマンドを実行できるかどうかを示す値。</returns>
        protected virtual bool CanRemove()
        {
            return this.Current != null && (
                (this.Mode == CommitMode.Single && !this.IsEditing) ||
                (this.Mode == CommitMode.Multiple && this.IsEditing)
            );
        }

        /// <summary>
        /// 削除 コマンドを実行します。
        /// </summary>
        protected virtual void Remove()
        {
            if (!Message.Confirm(MessageType.Warning, Messages.Delete)) return;

            if (this.Mode == CommitMode.Single)
            {
                try
                {
                    this.Remove(this.Current.Source);
                }
                catch (PrimaryKeyException)
                {
                    Message.Notify(MessageType.Error, Messages.PrimaryKeyException);
                }
                catch (ForeignKeyException)
                {
                    Message.Notify(MessageType.Error, Messages.ForeignKeyException);
                }
                catch (ConcurrencyException)
                {
                    Message.Notify(MessageType.Error, Messages.ConcurrencyException);
                }

                this.Refresh();
            }
            else if (this.Mode == CommitMode.Multiple)
            {
                if (this.Source.IsAddingNew) this.Source.CommitNew();
                if (this.Source.IsEditingItem) this.Source.CommitEdit();

                this.Source.Remove(this.Source.CurrentItem);
            }
        }

        /// <summary>
        /// 削除します。
        /// </summary>
        /// <param name="source">ソース。</param>
        protected virtual void Remove(TSource source) { }
        #endregion

        #region Validate
        /// <summary>
        /// 検証します。
        /// </summary>
        /// <returns>結果。</returns>
        public override bool Validate()
        {
            var result = base.Validate();

            if (this.Mode == CommitMode.Single)
            {
                if (!this.Current.Validate()) result = false;
            }
            else if (this.Mode == CommitMode.Multiple)
            {
                foreach (var value in this.Source.SourceCollection.OfType<TBindable>())
                {
                    if (!value.Validate()) result = false;
                }
            }

            return result;
        }
        #endregion

        #region Save
        /// <summary>
        /// コミット コマンドが実行可能かどうかを判断します。
        /// </summary>
        /// <returns>コマンドを実行できるかどうかを示す値。</returns>
        protected virtual bool CanCommit() { return this.IsEditing && this.Validate(); }

        /// <summary>
        /// コミット コマンドを実行します。
        /// </summary>
        protected virtual void Commit()
        {
            if (!Message.Confirm(MessageType.Question, Messages.Save)) return;

            this.IsEditing = false;

            try
            {
                if (this.Mode == CommitMode.Single)
                {
                    this.Commit(this.Current.Commit());
                }
                else if (this.Mode == CommitMode.Multiple)
                {
                    this.Commit(this.Source.SourceCollection.OfType<TBindable>().Select(value => { value.Commit(); return value.Source; }).ToList());
                }
            }
            catch (PrimaryKeyException)
            {
                Message.Notify(MessageType.Error, Messages.PrimaryKeyException);
            }
            catch (ForeignKeyException)
            {
                Message.Notify(MessageType.Error, Messages.ForeignKeyException);
            }
            catch (ConcurrencyException)
            {
                Message.Notify(MessageType.Error, Messages.ConcurrencyException);
            }

            this.Refresh();
        }

        /// <summary>
        /// コミットします。
        /// </summary>
        /// <param name="source">ソース。</param>
        protected virtual void Commit(TSource source) { }

        /// <summary>
        /// コミットします。
        /// </summary>
        /// <param name="source">ソース。</param>
        protected virtual void Commit(IEnumerable<TSource> source) { }
        #endregion

        #region Cancel
        /// <summary>
        /// ロールバック コマンドが実行可能かどうかを判断します。
        /// </summary>
        /// <returns>コマンドを実行できるかどうかを示す値。</returns>
        protected virtual bool CanRollback() { return this.IsEditing; }

        /// <summary>
        /// ロールバック コマンドを実行します。
        /// </summary>
        protected virtual void Rollback()
        {
            if (!this.IsEditing) return;

            this.IsEditing = false;

            if (this.Mode == CommitMode.Single)
            {
                if (this.Current != null && this.Current.Source != null)
                {
                    if (this.Current.Source.TimeStamp == null) this.CurrentBind();
                    else this.Current.Rollback();
                }
            }
            else if (this.Mode == CommitMode.Multiple)
            {
                this.Refresh();
            }
        }

        /// <summary>
        /// ロールバック コマンドを実行します。
        /// </summary>
        protected virtual bool Rollback(bool confirm)
        {
            if (this.IsEditing && !Message.Confirm(MessageType.Warning, Messages.Rollback)) return false;

            this.Rollback();

            return true;
        }
        #endregion

        #region Print
        /// <summary>
        /// 印刷 コマンドが実行可能かどうかを判断します。
        /// </summary>
        /// <returns>コマンドを実行できるかどうかを示す値。</returns>
        protected virtual bool CanPrint() { return !this.IsEditing && (this.Mode == CommitMode.Multiple || this.Current != null); }

        /// <summary>
        /// 印刷 コマンドを実行します。
        /// </summary>
        protected virtual void Print() { }
        #endregion

        #endregion
    }
}
ToDo: DeductionsViewModel
using Microsoft.Practices.Unity;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using Tact.Services;
using Tact.Windows.Mvvm;
using Tact.Windows.Regions;

namespace Tact.Windows.ViewModels
{
    /// <summary>
    /// 控除 ビューモデルを提供します。
    /// </summary>
    public class DeductionsViewModel : BindableCollection<Deduction, Models.Deduction>
    {
        #region Constructor
        /// <summary>
        /// 新しいインスタンスを初期化します。
        /// </summary>
        public DeductionsViewModel()
        {
            this.Mode = CommitMode.Multiple;
            this.Types = new ListCollectionView(new List<KeyValuePair<CustomerType, string>>());
            this.Customers = new ListCollectionView(new List<Models.Customer>());
            this.Costs = new ListCollectionView(new List<Models.Cost>());
            this.Cost = new Cost();
            this.CostTotal = new ListCollectionView(new List<Cost> { this.Cost });
            this.Requires = new ListCollectionView(new List<Deduction>());
            this.Deduction = new Deduction();
            this.DeductionTotal = new ListCollectionView(new List<Deduction> { this.Deduction });
            this.Value = new Deduction();
            this.Total = new ListCollectionView(new List<Deduction> { this.Value });

            this.RegisterRelation("Customer", "IsCustomerSelected");
        }
        #endregion

        #region Property
        /// <summary>
        /// 年月を取得または設定します。
        /// </summary>
        public string YearMonth
        {
            get { return this.GetProperty<string>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 年を取得または設定します。
        /// </summary>
        public string Year
        {
            get { return this.GetProperty<string>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 月を取得または設定します。
        /// </summary>
        public string Month
        {
            get { return this.GetProperty<string>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// タイプのコレクションを取得します。
        /// </summary>
        public ICollectionView Types
        {
            get { return this.GetProperty<ICollectionView>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// タイプを取得します。
        /// </summary>
        public CustomerType Type
        {
            get { return ((KeyValuePair<CustomerType, string>)this.Types.CurrentItem).Key; }
        }

        /// <summary>
        /// 取引先のコレクションのビューを取得します。
        /// </summary>
        public ListCollectionView Customers
        {
            get { return this.GetProperty<ListCollectionView>(); }
            set { var current = this.Customer; this.SetProperty(value); this.Customer = current; }
        }

        /// <summary>
        /// 取引先を取得します。
        /// </summary>
        public Models.Customer Customer
        {
            get { return (this.Customers == null) ? null : this.Customers.CurrentItem as Models.Customer; }
            set { if (this.Customers != null) this.Customers.MoveCurrentTo(value); }
        }

        /// <summary>
        /// 取引先が選択されているかどうかを示す値を取得します。
        /// </summary>
        public bool IsCustomerSelected
        {
            get { return this.Customer != null && !string.IsNullOrEmpty(this.Customer.Id); }
        }

        /// <summary>
        /// 終了日付を取得または設定します。
        /// </summary>
        public DateTime? Date
        {
            get { return this.GetProperty<DateTime?>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 開始日付を取得または設定します。
        /// </summary>
        public DateTime? FromDate
        {
            get { return this.GetProperty<DateTime?>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 終了日付を取得または設定します。
        /// </summary>
        public DateTime? ToDate
        {
            get { return this.GetProperty<DateTime?>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// コストのコレクションを取得します。
        /// </summary>
        public ListCollectionView Costs
        {
            get { return this.GetProperty<ListCollectionView>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// コストを取得します。
        /// </summary>
        public Cost Cost
        {
            get { return this.GetProperty<Cost>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// コストのビューを取得します。
        /// </summary>
        public ListCollectionView CostTotal
        {
            get { return this.GetProperty<ListCollectionView>(); }
            private set { this.SetProperty(value); }
        }

        /// <summary>
        /// 控除(必須)のコレクションを取得します。
        /// </summary>
        public ListCollectionView Requires
        {
            get { return this.GetProperty<ListCollectionView>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 控除を取得します。
        /// </summary>
        public Deduction Deduction
        {
            get { return this.GetProperty<Deduction>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 控除のビューを取得します。
        /// </summary>
        public ListCollectionView DeductionTotal
        {
            get { return this.GetProperty<ListCollectionView>(); }
            private set { this.SetProperty(value); }
        }

        /// <summary>
        /// 値を取得します。
        /// </summary>
        public Deduction Value
        {
            get { return this.GetProperty<Deduction>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 合計のビューを取得します。Total
        /// </summary>
        public ListCollectionView Total
        {
            get { return this.GetProperty<ListCollectionView>(); }
            private set { this.SetProperty(value); }
        }

        /// <summary>
        /// サービスを取得または設定します。
        /// </summary>
        [Dependency]
        public IDeductionService Service { get; set; }
        #endregion

        #region Method

        #region Activate
        /// <summary>
        /// 活性化するときに発生します。
        /// </summary>
        /// <param name="context">コンテキスト。</param>
        protected override void OnActivate(NavigationContext context)
        {
            this.Types.CurrentChanged -= this.OnTypeChanged;
            this.Types = new ListCollectionView(this.Service.Types.Select(value => new KeyValuePair<CustomerType, string>(value, value.Name())).ToList());
            this.Types.CurrentChanged += this.OnTypeChanged;

            base.OnActivate(context);

            this.Types.MoveCurrentToFirst();
            this.Customers.MoveCurrentToFirst();
        }
        #endregion

        #region Refresh
        /// <summary>
        /// 更新 コマンドを実行します。
        /// </summary>
        protected override void Refresh()
        {
            if (!this.Rollback(this.IsEditing)) return;

            this.YearMonth = Master.Setting(Application.Current.User).YearMonth;

            this.Year = (string.IsNullOrEmpty(this.YearMonth)) ? null : this.YearMonth.Substring(0, 4);
            this.Month = (string.IsNullOrEmpty(this.YearMonth)) ? null : this.YearMonth.Substring(4, 2);

            this.Customers.CurrentChanged -= this.OnCustomerChanged;
            this.Customers = new ListCollectionView(this.Service.Customers(this.YearMonth, Application.Current.User));
            this.Customers.CurrentChanged += this.OnCustomerChanged;

            this.Filtering();

            this.RefreshOverride();
        }

        /// <summary>
        /// 更新します。
        /// </summary>
        private void RefreshOverride()
        {
            var source = this.CurrentSource;

            this.Costs.CurrentChanged -= this.OnCurrentChanged;
            this.Source.CurrentChanged -= this.OnCurrentChanged;
            this.Requires.CurrentChanged -= this.OnCurrentChanged;

            this.Costs = new ListCollectionView(this.Service.Costs(this.YearMonth, this.Customer, Application.Current.User).ToList());
            this.Costs.MoveCurrentTo(null);

            base.Refresh();

            this.Source.Filter = (value => value is Deduction && !((Deduction)value).Required);
            this.Requires = new ListCollectionView(
                this.Source.SourceCollection.OfType<Deduction>().Where(value => value.Required).ToList()
            );
            this.Requires.MoveCurrentTo(null);

            this.Costs.CurrentChanged += this.OnCurrentChanged;
            this.Source.CurrentChanged += this.OnCurrentChanged;
            this.Requires.CurrentChanged += this.OnCurrentChanged;

            var current = this.Requires.OfType<Deduction>().FirstOrDefault(value => value.Source.Equals(source));
            if (current != null) this.Requires.MoveCurrentTo(current);

            this.Calculate();
        }

        /// <summary>
        /// 値のシーケンスをフィルター処理します。
        /// </summary>
        /// <returns>結果。</returns>
        protected override IEnumerable<Models.Deduction> Where()
        {
            var source = this.Service.Where(this.YearMonth, (this.Customer == null) ? null : this.Customer.Id, Application.Current.User).ToList();

            if (this.Customer != null && !string.IsNullOrEmpty(this.Customer.Id))
            {
                if (!source.Any(value => value.Number == (int)DeductionNumber.Transfer))
                {
                    source.Add(new Models.Deduction {
                        OfficeId = Application.Current.User.OfficeId,
                        YearMonth = this.YearMonth,
                        CustomerId = this.Customer.Id,
                        Number = (int)DeductionNumber.Transfer,
                        Value = 0
                    });
                }

                if (this.Customer.Type == CustomerType.Painting)
                {
                    source.Add(new Models.Deduction {
                        OfficeId = Application.Current.User.OfficeId,
                        YearMonth = this.YearMonth,
                        CustomerId = this.Customer.Id,
                        Number = (int)DeductionNumber.Membership,
                        Value = this.Costs.OfType<Models.Cost>().Sum(value => value.Value) * 0.005
                    });
                }
            }

            return source;
        }

        /// <summary>
        /// カレントを検索します。
        /// </summary>
        /// <returns>結果。</returns>
        protected override Models.Deduction Find()
        {
            return this.CurrentSource;
        }
        #endregion

        #region Filtering
        /// <summary>
        /// フィルタリングします。
        /// </summary>
        private void Filtering()
        {
            if (this.Customers == null) return;

            this.Customers.Filter = (value => value == null || ((Models.Customer)value).Type == this.Type);
        }
        #endregion

        #region Type
        /// <summary>
        /// タイプが変更される前にこのイベントが発生します。
        /// </summary>
        /// <param name="sender">イベントのソース。</param>
        /// <param name="e">イベントデータ。</param>
        private void OnTypeChanged(object sender, EventArgs e)
        {
            this.Filtering();

            this.ToDate = DateTime.ParseExact(this.YearMonth + ((this.Type == CustomerType.Painting) ? "10" : "20"), "yyyyMMdd", null);
            this.Date = this.ToDate.Value.AddMonths(1);
            this.FromDate = this.ToDate.Value.AddMonths(-1);
        }
        #endregion

        #region Customer
        /// <summary>
        /// 取引先が変更される前にこのイベントが発生します。
        /// </summary>
        /// <param name="sender">イベントのソース。</param>
        /// <param name="e">イベントデータ。</param>
        private void OnCustomerChanged(object sender, EventArgs e)
        {
            if (!this.Rollback(this.IsEditing)) return;

            this.RefreshOverride();

            this.RaisePropertyChanged("Customer");
            this.RaiseCanExecuteChanged(this.Commands.Edit);
        }
        #endregion

        #region Current
        /// <summary>
        /// カレントが変更された後にこのイベントが発生します。
        /// </summary>
        /// <param name="sender">イベントのソース。</param>
        /// <param name="e">イベントデータ。</param>
        private void OnCurrentChanged(object sender, EventArgs e)
        {
            if (sender == this.Costs && this.Costs.CurrentItem != null)
            {
                this.Source.MoveCurrentTo(null);
                this.Requires.MoveCurrentTo(null);
            }
            else if (sender == this.Source && this.Source.CurrentItem != null)
            {
                this.Costs.MoveCurrentTo(null);
                this.Requires.MoveCurrentTo(null);
            }
            else if (sender == this.Requires && this.Requires.CurrentItem != null)
            {
                this.Costs.MoveCurrentTo(null);
                this.Source.MoveCurrentTo(null);

                this.CurrentBind(this.Requires.CurrentItem);
            }
        }

        /// <summary>
        /// カレントのプロパティ値が変更されたときに発生します。
        /// </summary>
        /// <param name="sender">イベントのソース。</param>
        /// <param name="e">イベントデータ。</param>
        protected override void OnCurrentPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            this.Calculate();

            base.OnCurrentPropertyChanged(sender, e);
        }
        #endregion

        #region Calculate
        /// <summary>
        /// 計算します。
        /// </summary>
        private void Calculate()
        {
            this.Cost.Value = this.Costs.OfType<Models.Cost>().Sum(value => value.Value);
            this.Deduction.Value = this.Source.SourceCollection.OfType<Deduction>().Sum(value => value.Value);
            this.Value.Value = this.Cost.Value - this.Deduction.Value;
        }
        #endregion

        #region Edit
        /// <summary>
        /// 編集 コマンドが実行可能かどうかを判断します。
        /// </summary>
        /// <returns>コマンドを実行できるかどうかを示す値。</returns>
        protected override bool CanEdit() { return base.CanEdit() && this.IsCustomerSelected; }
        #endregion

        #region Add
        /// <summary>
        /// 生成します。
        /// </summary>
        /// <returns>結果。</returns>
        protected override Deduction Create()
        {
            var instance = new Deduction();

            instance.Office.Id = Application.Current.User.OfficeId;
            instance.YearMonth = this.YearMonth;
            instance.CustomerId = this.Customer.Id;

            var grouping = this.Source.SourceCollection.OfType<Deduction>().Where(value => !value.Required).ToList();

            instance.Number = (grouping.Count == 0) ? 1 : grouping.Max(value => value.Number) + 1;

            return instance;
        }
        #endregion

        #region Remove
        /// <summary>
        /// 削除 コマンドが実行可能かどうかを判断します。
        /// </summary>
        /// <returns>コマンドを実行できるかどうかを示す値。</returns>
        protected override bool CanRemove() { return base.CanRemove() && !this.Current.Required; }
        #endregion

        #region Commit
        /// <summary>
        /// コミットします。
        /// </summary>
        /// <param name="source">ソース。</param>
        protected override void Commit(IEnumerable<Models.Deduction> source)
        {
            this.Service.SaveChanges(this.YearMonth, this.Customer.Id, source, Application.Current.User);
        }
        #endregion

        #endregion
    }
}
ToDo: OrdersViewModel
using Microsoft.Practices.Unity;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using Tact.Services;
using Tact.Windows.Mvvm;
using Tact.Windows.Regions;
using Tact.Windows.Interactivity;

namespace Tact.Windows.ViewModels
{
    /// <summary>
    /// オーダー ビューモデルを提供します。
    /// </summary>
    public class OrdersViewModel : BindableCollection<Order, Models.Order>
    {
        #region Property
        /// <summary>
        /// フィルタを取得または設定します。
        /// </summary>
        public bool Filter
        {
            get { return this.GetProperty<bool>(); }
            set
            {
                if (object.Equals(this.Filter, value)) return;

                this.SetProperty(value);

                base.Refresh();

                this.Source.MoveCurrentToFirst();
            }
        }

        /// <summary>
        /// 担当ユーザーのコレクションのビューを取得します。
        /// </summary>
        public ICollectionView Users
        {
            get { return this.GetProperty<ICollectionView>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 営業ユーザーのコレクションのビューを取得します。
        /// </summary>
        public ICollectionView SalesUsers
        {
            get { return this.GetProperty<ICollectionView>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 受注先のコレクションのビューを取得します。
        /// </summary>
        public ICollectionView Orderers
        {
            get { return this.GetProperty<ICollectionView>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 元請のコレクションのビューを取得します。
        /// </summary>
        public ICollectionView Contractors
        {
            get { return this.GetProperty<ICollectionView>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// タイプのコレクションを取得します。
        /// </summary>
        public ICollectionView Types
        {
            get { return this.GetProperty<ICollectionView>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 用途のコレクションを取得します。
        /// </summary>
        public ICollectionView Uses
        {
            get { return this.GetProperty<ICollectionView>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// サービスを取得または設定します。
        /// </summary>
        [Dependency]
        public IOrderService Service { get; set; }
        #endregion

        #region Method
        /// <summary>
        /// 活性化するときに発生します。
        /// </summary>
        /// <param name="context">コンテキスト。</param>
        protected override void OnActivate(NavigationContext context)
        {
            this.SetProperty(false, "Filter");

            base.OnActivate(context);
        }

        /// <summary>
        /// 更新 コマンドを実行します。
        /// </summary>
        protected override void Refresh()
        {
            if (!this.Rollback(this.IsEditing)) return;

            var users = Master.Users(Application.Current.User);

            this.Users = new ListCollectionView(users);
            this.SalesUsers = new ListCollectionView(users);

            var customers = Master.Customers(CustomerType.Orderer);

            this.Orderers = new ListCollectionView(customers.ToList());
            this.Contractors = new ListCollectionView(customers.Where(value => !string.IsNullOrEmpty(value.Id)).ToList());
            this.Contractors.MoveCurrentTo(null);

            this.Types = new ListCollectionView(Master.OrderTypes());
            this.Uses = new ListCollectionView(Master.OrderUses());

            base.Refresh();
        }

        /// <summary>
        /// 値のシーケンスをフィルター処理します。
        /// </summary>
        /// <returns>結果。</returns>
        protected override IEnumerable<Models.Order> Where()
        {
            return this.Service.Where(Application.Current.User, this.Filter);
        }

        /// <summary>
        /// カレントを検索します。
        /// </summary>
        /// <returns>結果。</returns>
        protected override Models.Order Find()
        {
            return this.Service.Find(this.CurrentSource.Id, Application.Current.User);
        }

        /// <summary>
        /// 追加 コマンドを実行します。
        /// </summary>
        protected override void Add()
        {
            this.Contractors.MoveCurrentTo(null);

            base.Add();
        }

        /// <summary>
        /// 生成します。
        /// </summary>
        /// <returns>結果。</returns>
        protected override Order Create()
        {
            var instance = new Order();

            instance.Office.Id = Application.Current.User.OfficeId;
            instance.UserId = Application.Current.User.Id;

            return instance;
        }

        /// <summary>
        /// 編集 コマンドを実行します。
        /// </summary>
        protected override void Edit()
        {
            this.Contractors.MoveCurrentTo(null);

            base.Edit();
        }

        /// <summary>
        /// 削除します。
        /// </summary>
        /// <param name="source">ソース。</param>
        protected override void Remove(Models.Order source)
        {
            this.Service.Remove(source, Application.Current.User);
        }

        /// <summary>
        /// コミットします。
        /// </summary>
        /// <param name="source">ソース。</param>
        protected override void Commit(Models.Order source)
        {
            this.Service.AddOrUpdate(source, Application.Current.User);
        }
        #endregion
    }
}
ToDo: PerformancesViewModel
using Microsoft.Practices.Unity;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using Tact.Services;
using Tact.Windows.Mvvm;
using Tact.Windows.Regions;
using Tact.Windows.Interactivity;

namespace Tact.Windows.ViewModels
{
    /// <summary>
    /// 実績 ビューモデルを提供します。
    /// </summary>
    public class PerformancesViewModel : BindableCollection<Order, Models.Order>
    {
        #region Property
        /// <summary>
        /// フィルタを取得または設定します。
        /// </summary>
        public bool Filter
        {
            get { return this.GetProperty<bool>(); }
            set
            {
                if (object.Equals(this.Filter, value)) return;

                this.SetProperty(value);

                base.Refresh();

                this.Source.MoveCurrentToFirst();
            }
        }

        /// <summary>
        /// 担当ユーザーのコレクションのビューを取得します。
        /// </summary>
        public ICollectionView Users
        {
            get { return this.GetProperty<ICollectionView>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 営業ユーザーのコレクションのビューを取得します。
        /// </summary>
        public ICollectionView SalesUsers
        {
            get { return this.GetProperty<ICollectionView>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 受注先のコレクションのビューを取得します。
        /// </summary>
        public ICollectionView Orderers
        {
            get { return this.GetProperty<ICollectionView>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 元請のコレクションのビューを取得します。
        /// </summary>
        public ICollectionView Contractors
        {
            get { return this.GetProperty<ICollectionView>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// タイプのコレクションを取得します。
        /// </summary>
        public ICollectionView Types
        {
            get { return this.GetProperty<ICollectionView>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 用途のコレクションを取得します。
        /// </summary>
        public ICollectionView Uses
        {
            get { return this.GetProperty<ICollectionView>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// サービスを取得または設定します。
        /// </summary>
        [Dependency]
        public IPerformanceService Service { get; set; }
        #endregion

        #region Method
        /// <summary>
        /// 活性化するときに発生します。
        /// </summary>
        /// <param name="context">コンテキスト。</param>
        protected override void OnActivate(NavigationContext context)
        {
            this.SetProperty(false, "Filter");

            base.OnActivate(context);
        }

        /// <summary>
        /// 更新 コマンドを実行します。
        /// </summary>
        protected override void Refresh()
        {
            if (!this.Rollback(this.IsEditing)) return;

            var users = Master.Users(Application.Current.User);

            this.Users = new ListCollectionView(users);
            this.SalesUsers = new ListCollectionView(users);

            var customers = Master.Customers(CustomerType.Orderer);

            this.Orderers = new ListCollectionView(customers.ToList());
            this.Contractors = new ListCollectionView(customers.Where(value => !string.IsNullOrEmpty(value.Id)).ToList());
            this.Contractors.MoveCurrentTo(null);

            this.Types = new ListCollectionView(Master.OrderTypes());
            this.Uses = new ListCollectionView(Master.OrderUses());

            base.Refresh();
        }

        /// <summary>
        /// 値のシーケンスをフィルター処理します。
        /// </summary>
        /// <returns>結果。</returns>
        protected override IEnumerable<Models.Order> Where()
        {
            return this.Service.Where(Application.Current.User, this.Filter);
        }

        /// <summary>
        /// カレントを検索します。
        /// </summary>
        /// <returns>結果。</returns>
        protected override Models.Order Find()
        {
            return this.Service.Find(this.CurrentSource.Id, Application.Current.User);
        }

        /// <summary>
        /// 追加 コマンドを実行します。
        /// </summary>
        protected override void Add()
        {
            this.Contractors.MoveCurrentTo(null);

            base.Add();
        }

        /// <summary>
        /// 生成します。
        /// </summary>
        /// <returns>結果。</returns>
        protected override Order Create()
        {
            var instance = new Order();

            instance.Office.Id = Application.Current.User.OfficeId;

            return instance;
        }

        /// <summary>
        /// 編集 コマンドを実行します。
        /// </summary>
        protected override void Edit()
        {
            this.Contractors.MoveCurrentTo(null);

            base.Edit();
        }

        /// <summary>
        /// 追加 コマンドが実行可能かどうかを判断します。
        /// </summary>
        /// <returns>コマンドを実行できるかどうかを示す値。</returns>
        protected override bool CanAdd() { return false; }

        /// <summary>
        /// 削除 コマンドが実行可能かどうかを判断します。
        /// </summary>
        /// <returns>コマンドを実行できるかどうかを示す値。</returns>
        protected override bool CanRemove() { return false; }

        /// <summary>
        /// コミットします。
        /// </summary>
        /// <param name="source">ソース。</param>
        protected override void Commit(Models.Order source)
        {
            this.Service.AddOrUpdate(source, Application.Current.User);
        }
        #endregion
    }
}
ToDo: CustomersViewModel
using Microsoft.Practices.Unity;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Data;
using Tact.Services;
using Tact.Windows.Mvvm;
using Tact.Windows.Regions;

namespace Tact.Windows.ViewModels
{
    /// <summary>
    /// 取引先 ビューモデルを提供します。
    /// </summary>
    public class CustomersViewModel : BindableCollection<Customer, Models.Customer>
    {
        #region Constructor
        /// <summary>
        /// 新しいインスタンスを初期化します。
        /// </summary>
        static CustomersViewModel()
        {
            Setting = new Dictionary<NavigationContents, IEnumerable<CustomerType>>();

            Setting[NavigationContents.Orderer] = new List<CustomerType> {
                CustomerType.Orderer,
            };
            Setting[NavigationContents.Outsourcee] = new List<CustomerType> {
                CustomerType.Painting,
                CustomerType.Outsourcee,
            };
            Setting[NavigationContents.OtherCustomer] = new List<CustomerType> {
                CustomerType.Material,
                CustomerType.Field,
                CustomerType.Direct,
            };
        }
        #endregion

        #region Property
        /// <summary>
        /// 設定を取得または設定します。
        /// </summary>
        private static Dictionary<NavigationContents, IEnumerable<CustomerType>> Setting { get; set; }

        /// <summary>
        /// キーを取得します。
        /// </summary>
        public NavigationContents? Key
        {
            get { return this.GetProperty<NavigationContents?>(); }
            private set { this.SetProperty(value); }
        }

        /// <summary>
        /// パラメーターを取得します。
        /// </summary>
        private IEnumerable<CustomerType> Parameters
        {
            get { return Setting[this.Key.Value]; }
        }

        /// <summary>
        /// フィルタを取得または設定します。
        /// </summary>
        public string Filter
        {
            get { return this.GetProperty<string>(); }
            set { this.SetProperty(value); this.Filtering(); }
        }

        /// <summary>
        /// タイプのコレクションを取得します。
        /// </summary>
        public ICollectionView Types
        {
            get { return this.GetProperty<ICollectionView>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// 宛名のコレクションを取得します。
        /// </summary>
        public ICollectionView Suffixes
        {
            get { return this.GetProperty<ICollectionView>(); }
            set { this.SetProperty(value); }
        }

        /// <summary>
        /// サービスを取得または設定します。
        /// </summary>
        [Dependency]
        public ICustomerService Service { get; set; }
        #endregion

        #region Method
        /// <summary>
        /// 活性化のターゲットになるかどうかを返します。
        /// </summary>
        /// <param name="context">コンテキスト。</param>
        /// <returns>結果。</returns>
        protected override bool IsActivateTarget(NavigationContext context)
        {
            return this.Key == (NavigationContents?)context.Parameters["key"];
        }

        /// <summary>
        /// 活性化するときに発生します。
        /// </summary>
        /// <param name="context">コンテキスト。</param>
        protected override void OnActivate(NavigationContext context)
        {
            this.Key = (NavigationContents?)context.Parameters["key"];
            this.Filter = null;

            base.OnActivate(context);
        }

        /// <summary>
        /// 更新 コマンドを実行します。
        /// </summary>
        protected override void Refresh()
        {
            if (!this.Rollback(this.IsEditing)) return;

            this.Types = new ListCollectionView(this.Parameters.Select(value => new KeyValuePair<CustomerType, string>(value, value.Name())).ToList());
            this.Suffixes = new ListCollectionView(Master.Suffixes());

            base.Refresh();

            this.Filtering();
        }

        /// <summary>
        /// 値のシーケンスをフィルター処理します。
        /// </summary>
        /// <returns>結果。</returns>
        protected override IEnumerable<Models.Customer> Where()
        {
            return this.Service.Where(this.Parameters, Application.Current.User);
        }

        /// <summary>
        /// カレントを検索します。
        /// </summary>
        /// <returns>結果。</returns>
        protected override Models.Customer Find()
        {
            return this.Service.Find(this.CurrentSource.Id, Application.Current.User);
        }

        /// <summary>
        /// フィルタリングします。
        /// </summary>
        private void Filtering()
        {
            if (this.Source == null) return;

            this.Source.Filter = (string.IsNullOrEmpty(this.Filter)) ? (Predicate<object>)null : (value => {
                var source = value as Models.Customer;

                var regex = new Regex(this.Filter.KatakanaHalf(), RegexOptions.IgnoreCase);

                return regex.IsMatch(source.Name.KatakanaHalf()) || regex.IsMatch(source.NameKana.KatakanaHalf());
            });
        }

        /// <summary>
        /// 生成します。
        /// </summary>
        /// <returns>結果。</returns>
        protected override Customer Create()
        {
            var instance = new Customer();

            instance.Office.Id = Application.Current.User.OfficeId;
            instance.Type = this.Parameters.FirstOrDefault();

            return instance;
        }

        /// <summary>
        /// 削除します。
        /// </summary>
        /// <param name="source">ソース。</param>
        protected override void Remove(Models.Customer source)
        {
            this.Service.Remove(source, Application.Current.User);
        }

        /// <summary>
        /// コミットします。
        /// </summary>
        /// <param name="source">ソース。</param>
        protected override void Commit(Models.Customer source)
        {
            this.Service.AddOrUpdate(source, Application.Current.User);
        }
        #endregion
    }
}
ToDo: Performances
<UserControl
    x:Class="Tact.Windows.Views.Performances"
    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"
    xmlns:Interactivity="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:Prism="http://prismlibrary.com/"
    xmlns:Views="clr-namespace:Tact.Windows.Views"
    xmlns:Models="clr-namespace:Tact.Windows.ViewModels"
    d:DataContext="{d:DesignInstance {x:Type Models:PerformancesViewModel}, IsDesignTimeCreatable=True}"
    d:DesignWidth="1280" d:DesignHeight="720"
    Prism:ViewModelLocator.AutoWireViewModel="True">
    <Grid Style="{StaticResource ContentGridStyle}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="256"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Border Grid.Column="0">
            <DockPanel>
                <ResponsiveGrid DockPanel.Dock="Top">
                    <DockPanel ResponsiveGrid.ColumnSpan="12">
                        <CheckBox x:Name="Filter" IsChecked="{Binding Filter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding IsReadOnly}">完成計上済工事</CheckBox>
                    </DockPanel>
                </ResponsiveGrid>
                <ListView ItemsSource="{Binding Source}">
                    <Interactivity:Interaction.Behaviors>
                        <Interactivity:ListViewAutoResizeBehavior/>
                        <Interactivity:ListViewAutoScrollBehavior/>
                    </Interactivity:Interaction.Behaviors>
                    <ListView.Resources>
                        <DataTemplate x:Key="Id" DataType="{x:Type Models:Order}">
                            <TextBlock Text="{Binding Id}" Style="{StaticResource AsideStyle}"/>
                        </DataTemplate>
                        <DataTemplate x:Key="Name" DataType="{x:Type Models:Order}">
                            <TextBlock Text="{Binding Orderer.Name}"/>
                        </DataTemplate>
                        <Style x:Key="Container" TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource {x:Type ListViewItem}}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type ListViewItem}">
                                        <Border Name="Border" Style="{StaticResource ItemBorderStyle}">
                                            <StackPanel>
                                                <GridViewRowPresenter Content="{TemplateBinding Content}" Columns="{TemplateBinding GridView.ColumnCollection}"/>
                                                <TextBlock Text="{Binding Name}" Style="{StaticResource AsideIndentStyle}"/>
                                            </StackPanel>
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsSelected" Value="True">
                                                <Setter TargetName="Border" Property="Background" Value="{DynamicResource HighlightBackground}"/>
                                                <Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource ActiveBorder}"/>
                                                <Setter TargetName="Border" Property="BorderThickness" Value="3,0,0,0"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ListView.Resources>
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Header="ID" CellTemplate="{StaticResource Id}"/>
                            <GridViewColumn Header="受注先" CellTemplate="{StaticResource Name}"/>
                        </GridView>
                    </ListView.View>
                    <ListView.ItemContainerStyle>
                        <Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource Container}"/>
                    </ListView.ItemContainerStyle>
                </ListView>
            </DockPanel>
        </Border>
        <GridSplitter Grid.Column="1" Style="{StaticResource VerticalSplitterStyle}"/>
        <Border Grid.Column="2" Style="{StaticResource ContentBorderStyle}">
            <ContentControl Content="{Binding Current}" Focusable="False">
                <ContentControl.ContentTemplate>
                    <DataTemplate DataType="{x:Type Models:Order}">
                        <StackPanel x:Name="Content" Orientation="Vertical">
                            <Interactivity:Interaction.Behaviors>
                                <Interactivity:FocusBehavior/>
                            </Interactivity:Interaction.Behaviors>
                            <ResponsiveGrid>
                                <ResponsiveGrid.Resources>
                                    <Style TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}">
                                        <Setter Property="Width" Value="96"/>
                                    </Style>
                                </ResponsiveGrid.Resources>
                                <DockPanel ResponsiveGrid.ColumnSpan="6" LastChildFill="False">
                                    <Label>ID :</Label>
                                    <TextBlock x:Name="IdView" Text="{Binding Text, ElementName=Id}"/>
                                    <TextBox x:Name="Id" Text="{Binding Id, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="64" MaxLength="6"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="6" LastChildFill="False">
                                    <Label>見積番号 :</Label>
                                    <TextBlock x:Name="ProjectView" Text="{Binding Text, ElementName=Project}"/>
                                    <TextBox x:Name="Project" Text="{Binding ProjectId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="96" MaxLength="9"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>工事担当者 :</Label>
                                    <TextBlock x:Name="UserView" Text="{Binding Text, ElementName=User}"/>
                                    <ComboBox x:Name="User" SelectedValue="{Binding UserId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                        ItemsSource="{Binding DataContext.Users, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}, UpdateSourceTrigger=PropertyChanged}"
                                        DisplayMemberPath="Name" SelectedValuePath="Id"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>営業担当者 :</Label>
                                    <TextBlock x:Name="SalesUserView" Text="{Binding Text, ElementName=SalesUser}"/>
                                    <ComboBox x:Name="SalesUser" SelectedValue="{Binding SalesUserId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                        ItemsSource="{Binding DataContext.SalesUsers, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}, UpdateSourceTrigger=PropertyChanged}"
                                        DisplayMemberPath="Name" SelectedValuePath="Id"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>工事名 :</Label>
                                    <TextBlock x:Name="NameView" Text="{Binding Text, ElementName=Name}"/>
                                    <TextBox x:Name="Name" Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="64"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>設計事務所 :</Label>
                                    <TextBlock x:Name="DesignOfficeView" Text="{Binding Text, ElementName=DesignOffice}"/>
                                    <TextBox x:Name="DesignOffice" Text="{Binding DesignOffice, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="64"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>受注先 :</Label>
                                    <TextBlock x:Name="OrdererView" Text="{Binding Text, ElementName=Orderer}"/>
                                    <ComboBox x:Name="Orderer" SelectedValue="{Binding OrdererId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                        ItemsSource="{Binding DataContext.Orderers, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}, UpdateSourceTrigger=PropertyChanged}"
                                        DisplayMemberPath="Name" SelectedValuePath="Id"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>元請 :</Label>
                                    <TextBlock x:Name="ContractorView" Text="{Binding Text, ElementName=Contractor}"/>
                                    <ComboBox x:Name="Contractor" SelectedValue="{Binding ContractorId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                        Text="{Binding ContractorName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                        ItemsSource="{Binding DataContext.Contractors, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}, UpdateSourceTrigger=PropertyChanged}"
                                        DisplayMemberPath="Name" SelectedValuePath="Id" IsEditable="True"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12">
                                    <Border Style="{StaticResource SeparatorBorderStyle}"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12">
                                    <Label>住所 :</Label>
                                    <TextBlock x:Name="AddressView" Text="{Binding Text, ElementName=Address}"/>
                                    <TextBox x:Name="Address" Text="{Binding Address, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="128"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>電話 :</Label>
                                    <TextBlock x:Name="PhoneNumberView" Text="{Binding Text, ElementName=PhoneNumber}"/>
                                    <TextBox x:Name="PhoneNumber" Text="{Binding PhoneNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="16"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>Fax :</Label>
                                    <TextBlock x:Name="FaxNumberView" Text="{Binding Text, ElementName=FaxNumber}"/>
                                    <TextBox x:Name="FaxNumber" Text="{Binding FaxNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="16"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>工期 :</Label>
                                    <TextBlock x:Name="FromDateView" Text="{Binding Text, ElementName=FromDate}"/>
                                    <DatePicker x:Name="FromDate" SelectedDate="{Binding FromDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>～</Label>
                                    <TextBlock x:Name="ToDateView" Text="{Binding Text, ElementName=ToDate}"/>
                                    <DatePicker x:Name="ToDate" SelectedDate="{Binding ToDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>種類 :</Label>
                                    <TextBlock x:Name="TypeView" Text="{Binding Text, ElementName=Type}"/>
                                    <ComboBox x:Name="Type" SelectedValue="{Binding Type, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                        ItemsSource="{Binding DataContext.Types, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}"
                                        DisplayMemberPath="Name" SelectedValuePath="Value"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>用途 :</Label>
                                    <TextBlock x:Name="UseView" Text="{Binding Text, ElementName=Use}"/>
                                    <ComboBox x:Name="Use" SelectedValue="{Binding Use, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                        ItemsSource="{Binding DataContext.Uses, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}"
                                        DisplayMemberPath="Name" SelectedValuePath="Value"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12">
                                    <Border Style="{StaticResource SeparatorBorderStyle}"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>受注額 :</Label>
                                    <TextBlock x:Name="FixedValueView" Text="{Binding FixedValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}"/>
                                    <TextBox x:Name="FixedValue" Text="{Binding FixedValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>見積額 :</Label>
                                    <TextBlock x:Name="QuotedValueView" Text="{Binding QuotedValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}"/>
                                    <TextBox x:Name="QuotedValue" Text="{Binding QuotedValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12">
                                    <Border Style="{StaticResource SeparatorBorderStyle}"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>完成年月:</Label>
                                    <TextBlock x:Name="DateView" Text="{Binding Text, ElementName=Date}"/>
                                    <DatePicker x:Name="Date" SelectedDate="{Binding Performed.Date, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>完工額 :</Label>
                                    <TextBlock x:Name="ValueView" Text="{Binding Performed.Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}"/>
                                    <TextBox x:Name="Value" Text="{Binding Performed.Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12">
                                    <Grid DockPanel.Dock="Left">
                                        <Grid.Resources>
                                            <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
                                                <Setter Property="BorderThickness" Value="0"/>
                                                <Setter Property="MinHeight" Value="0"/>
                                                <Setter Property="Height" Value="21"/>
                                                <Setter Property="Padding" Value="1,1,1,1"/>
                                                <Setter Property="VerticalAlignment" Value="Center"/>
                                                <Setter Property="VerticalContentAlignment" Value="Center"/>
                                            </Style>
                                        </Grid.Resources>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="96"/>
                                            <ColumnDefinition Width="96"/>
                                            <ColumnDefinition Width="96"/>
                                            <ColumnDefinition Width="96"/>
                                            <ColumnDefinition Width="96"/>
                                            <ColumnDefinition Width="96"/>
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto"/>
                                            <RowDefinition Height="Auto"/>
                                        </Grid.RowDefinitions>
                                        <Border Grid.Row="0" Grid.Column="0" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="1,1,1,1" Background="{DynamicResource GrayBackground}">
                                            <Label>外注費</Label>
                                        </Border>
                                        <Border Grid.Row="0" Grid.Column="1" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="0,1,1,1" Background="{DynamicResource GrayBackground}">
                                            <Label>材料費</Label>
                                        </Border>
                                        <Border Grid.Row="0" Grid.Column="2" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="0,1,1,1" Background="{DynamicResource GrayBackground}">
                                            <Label>現場経費</Label>
                                        </Border>
                                        <Border Grid.Row="0" Grid.Column="3" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="0,1,1,1" Background="{DynamicResource GrayBackground}">
                                            <Label>直用工経費</Label>
                                        </Border>
                                        <Border Grid.Row="0" Grid.Column="4" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="0,1,1,1" Background="{DynamicResource GrayBackground}">
                                            <Label>原価合計</Label>
                                        </Border>
                                        <Border Grid.Row="0" Grid.Column="5" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="0,1,1,1" Background="{DynamicResource GrayBackground}">
                                            <Label>利益率</Label>
                                        </Border>
                                        <Border Grid.Row="1" Grid.Column="0" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="1,0,1,1" Background="{DynamicResource Background}">
                                            <TextBox Text="{Binding OutsourcingCost, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}" TextAlignment="Right" IsReadOnly="True" Focusable="False"/>
                                        </Border>
                                        <Border Grid.Row="1" Grid.Column="1" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="0,0,1,1" Background="{DynamicResource Background}">
                                            <TextBox Text="{Binding MaterialCost, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}" TextAlignment="Right" IsReadOnly="True" Focusable="False"/>
                                        </Border>
                                        <Border Grid.Row="1" Grid.Column="2" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="0,0,1,1" Background="{DynamicResource Background}">
                                            <TextBox Text="{Binding FieldCost, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}" TextAlignment="Right" IsReadOnly="True" Focusable="False"/>
                                        </Border>
                                        <Border Grid.Row="1" Grid.Column="3" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="0,0,1,1" Background="{DynamicResource Background}">
                                            <TextBox Text="{Binding DirectCost, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}" TextAlignment="Right" IsReadOnly="True" Focusable="False"/>
                                        </Border>
                                        <Border Grid.Row="1" Grid.Column="4" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="0,0,1,1" Background="{DynamicResource Background}">
                                            <TextBox Text="{Binding TotalCost, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}" TextAlignment="Right" IsReadOnly="True" Focusable="False"/>
                                        </Border>
                                        <Border Grid.Row="1" Grid.Column="5" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="0,0,1,1" Background="{DynamicResource Background}">
                                            <TextBox Text="{Binding Profitability, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:0.0%}}" TextAlignment="Right" IsReadOnly="True" Focusable="False"/>
                                        </Border>
                                    </Grid>
                                    <Grid/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12">
                                    <Grid DockPanel.Dock="Left">
                                        <Grid.Resources>
                                            <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
                                                <Setter Property="BorderThickness" Value="0"/>
                                                <Setter Property="MinHeight" Value="0"/>
                                                <Setter Property="Height" Value="21"/>
                                                <Setter Property="Padding" Value="1,1,1,1"/>
                                                <Setter Property="VerticalAlignment" Value="Center"/>
                                                <Setter Property="VerticalContentAlignment" Value="Center"/>
                                            </Style>
                                        </Grid.Resources>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="96"/>
                                            <ColumnDefinition Width="96"/>
                                            <ColumnDefinition Width="96"/>
                                            <ColumnDefinition Width="96"/>
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto"/>
                                            <RowDefinition Height="Auto"/>
                                        </Grid.RowDefinitions>
                                        <Border Grid.Row="0" Grid.Column="0" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="1,1,1,1" Background="{DynamicResource GrayBackground}">
                                            <Label HorizontalAlignment="Center">請求額合計</Label>
                                        </Border>
                                        <Border Grid.Row="0" Grid.Column="1" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="0,1,1,1" Background="{DynamicResource Background}">
                                            <TextBox Text="{Binding InvoicedValue, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}" TextAlignment="Right" IsReadOnly="True" Focusable="False"/>
                                        </Border>
                                        <Border Grid.Row="0" Grid.Column="2" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="0,1,1,1" Background="{DynamicResource GrayBackground}">
                                            <Label HorizontalAlignment="Center">未請求額</Label>
                                        </Border>
                                        <Border Grid.Row="0" Grid.Column="3" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="0,1,1,1" Background="{DynamicResource Background}">
                                            <TextBox Text="{Binding UninvoicedValue, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}" TextAlignment="Right" IsReadOnly="True" Focusable="False"/>
                                        </Border>
                                        <Border Grid.Row="1" Grid.Column="0" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="1,0,1,1" Background="{DynamicResource GrayBackground}">
                                            <Label HorizontalAlignment="Center">入金合計</Label>
                                        </Border>
                                        <Border Grid.Row="1" Grid.Column="1" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="0,0,1,1" Background="{DynamicResource Background}">
                                            <TextBox Text="{Binding ReceiptedValue, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}" TextAlignment="Right" IsReadOnly="True" Focusable="False"/>
                                        </Border>
                                        <Border Grid.Row="1" Grid.Column="2" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="0,0,1,1" Background="{DynamicResource GrayBackground}">
                                            <Label HorizontalAlignment="Center">未収入金額</Label>
                                        </Border>
                                        <Border Grid.Row="1" Grid.Column="3" BorderBrush="{DynamicResource ControlBorder}" BorderThickness="0,0,1,1" Background="{DynamicResource Background}">
                                            <TextBox Text="{Binding UnreceiptedValue, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}" TextAlignment="Right" IsReadOnly="True" Focusable="False"/>
                                        </Border>
                                    </Grid>
                                    <Grid/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12">
                                    <Border Style="{StaticResource SeparatorBorderStyle}"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12">
                                    <Label>備考 :</Label>
                                    <TextBlock x:Name="RemarksView" Text="{Binding Text, ElementName=Remarks}"/>
                                    <TextBox x:Name="Remarks" Text="{Binding Performed.Remarks, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="64"/>
                                </DockPanel>
                            </ResponsiveGrid>
                        </StackPanel>
                        <DataTemplate.Triggers>
                            <Trigger Property="DataContext" Value="{x:Null}">
                                <Setter Property="Visibility" TargetName="Content" Value="Collapsed"/>
                            </Trigger>
                            <DataTrigger Binding="{Binding DataContext.IsEditing, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}" Value="False">
                                <Setter Property="Visibility" TargetName="Id" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Project" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="User" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="SalesUser" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Name" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="DesignOffice" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Orderer" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Contractor" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Address" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="PhoneNumber" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="FaxNumber" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="FromDate" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="ToDate" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Type" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Use" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="FixedValue" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="QuotedValue" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Date" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Value" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Remarks" Value="Collapsed"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding DataContext.IsEditing, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}" Value="True">
                                <Setter Property="Visibility" TargetName="Id" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Project" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="User" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="SalesUser" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Name" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="DesignOffice" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Orderer" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Contractor" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Address" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="PhoneNumber" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="FaxNumber" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="FromDate" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="ToDate" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Type" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Use" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="FixedValue" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="QuotedValue" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="DateView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="ValueView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="RemarksView" Value="Collapsed"/>
                            </DataTrigger>
                            <MultiDataTrigger>
                                <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding DataContext.IsEditing, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}" Value="True"/>
                                    <Condition Binding="{Binding IsNew}" Value="False"/>
                                </MultiDataTrigger.Conditions>
                                <Setter Property="Visibility" TargetName="IdView" Value="Visible"/>
                                <Setter Property="Visibility" TargetName="ProjectView" Value="Visible"/>
                                <Setter Property="Visibility" TargetName="Id" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Project" Value="Collapsed"/>
                            </MultiDataTrigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>
                </ContentControl.ContentTemplate>
            </ContentControl>
        </Border>
    </Grid>
</UserControl>
ToDo: Orders
<UserControl
    x:Class="Tact.Windows.Views.Orders"
    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"
    xmlns:Interactivity="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:Prism="http://prismlibrary.com/"
    xmlns:Views="clr-namespace:Tact.Windows.Views"
    xmlns:Models="clr-namespace:Tact.Windows.ViewModels"
    d:DataContext="{d:DesignInstance {x:Type Models:OrdersViewModel}, IsDesignTimeCreatable=True}"
    d:DesignWidth="1280" d:DesignHeight="720"
    Prism:ViewModelLocator.AutoWireViewModel="True">
    <Grid Style="{StaticResource ContentGridStyle}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="256"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Border Grid.Column="0">
            <DockPanel>
                <ResponsiveGrid DockPanel.Dock="Top">
                    <DockPanel ResponsiveGrid.ColumnSpan="12">
                        <CheckBox x:Name="Filter" IsChecked="{Binding Filter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding IsReadOnly}">完成計上済工事</CheckBox>
                    </DockPanel>
                </ResponsiveGrid>
                <ListView ItemsSource="{Binding Source}">
                    <Interactivity:Interaction.Behaviors>
                        <Interactivity:ListViewAutoResizeBehavior/>
                        <Interactivity:ListViewAutoScrollBehavior/>
                    </Interactivity:Interaction.Behaviors>
                    <ListView.Resources>
                        <DataTemplate x:Key="Id" DataType="{x:Type Models:Order}">
                            <TextBlock Text="{Binding Id}" Style="{StaticResource AsideStyle}"/>
                        </DataTemplate>
                        <DataTemplate x:Key="Name" DataType="{x:Type Models:Order}">
                            <TextBlock Text="{Binding Orderer.Name}"/>
                        </DataTemplate>
                        <Style x:Key="Container" TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource {x:Type ListViewItem}}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type ListViewItem}">
                                        <Border Name="Border" Style="{StaticResource ItemBorderStyle}">
                                            <StackPanel>
                                                <GridViewRowPresenter Content="{TemplateBinding Content}" Columns="{TemplateBinding GridView.ColumnCollection}"/>
                                                <TextBlock Text="{Binding Name}" Style="{StaticResource AsideIndentStyle}"/>
                                            </StackPanel>
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsSelected" Value="True">
                                                <Setter TargetName="Border" Property="Background" Value="{DynamicResource HighlightBackground}"/>
                                                <Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource ActiveBorder}"/>
                                                <Setter TargetName="Border" Property="BorderThickness" Value="3,0,0,0"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ListView.Resources>
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Header="ID" CellTemplate="{StaticResource Id}"/>
                            <GridViewColumn Header="受注先" CellTemplate="{StaticResource Name}"/>
                        </GridView>
                    </ListView.View>
                    <ListView.ItemContainerStyle>
                        <Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource Container}"/>
                    </ListView.ItemContainerStyle>
                </ListView>
            </DockPanel>
        </Border>
        <GridSplitter Grid.Column="1" Style="{StaticResource VerticalSplitterStyle}"/>
        <Border Grid.Column="2" Style="{StaticResource ContentBorderStyle}">
            <ContentControl Content="{Binding Current}" Focusable="False">
                <ContentControl.ContentTemplate>
                    <DataTemplate DataType="{x:Type Models:Order}">
                        <StackPanel x:Name="Content" Orientation="Vertical">
                            <Interactivity:Interaction.Behaviors>
                                <Interactivity:FocusBehavior/>
                            </Interactivity:Interaction.Behaviors>
                            <ResponsiveGrid>
                                <ResponsiveGrid.Resources>
                                    <Style TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}">
                                        <Setter Property="Width" Value="96"/>
                                    </Style>
                                </ResponsiveGrid.Resources>
                                <DockPanel ResponsiveGrid.ColumnSpan="6" LastChildFill="False">
                                    <Label>ID :</Label>
                                    <TextBlock x:Name="IdView" Text="{Binding Text, ElementName=Id}"/>
                                    <TextBox x:Name="Id" Text="{Binding Id, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="64" MaxLength="6"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="6" LastChildFill="False">
                                    <Label>見積番号 :</Label>
                                    <TextBlock x:Name="ProjectView" Text="{Binding Text, ElementName=Project}"/>
                                    <TextBox x:Name="Project" Text="{Binding ProjectId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="96" MaxLength="9"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>工事担当者 :</Label>
                                    <TextBlock x:Name="UserView" Text="{Binding Text, ElementName=User}"/>
                                    <ComboBox x:Name="User" SelectedValue="{Binding UserId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                        ItemsSource="{Binding DataContext.Users, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}, UpdateSourceTrigger=PropertyChanged}"
                                        DisplayMemberPath="Name" SelectedValuePath="Id"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>営業担当者 :</Label>
                                    <TextBlock x:Name="SalesUserView" Text="{Binding Text, ElementName=SalesUser}"/>
                                    <ComboBox x:Name="SalesUser" SelectedValue="{Binding SalesUserId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                        ItemsSource="{Binding DataContext.SalesUsers, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}, UpdateSourceTrigger=PropertyChanged}"
                                        DisplayMemberPath="Name" SelectedValuePath="Id"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>工事名 :</Label>
                                    <TextBlock x:Name="NameView" Text="{Binding Text, ElementName=Name}"/>
                                    <TextBox x:Name="Name" Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="64"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>設計事務所 :</Label>
                                    <TextBlock x:Name="DesignOfficeView" Text="{Binding Text, ElementName=DesignOffice}"/>
                                    <TextBox x:Name="DesignOffice" Text="{Binding DesignOffice, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="64"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>受注先 :</Label>
                                    <TextBlock x:Name="OrdererView" Text="{Binding Text, ElementName=Orderer}"/>
                                    <ComboBox x:Name="Orderer" SelectedValue="{Binding OrdererId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                        ItemsSource="{Binding DataContext.Orderers, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}, UpdateSourceTrigger=PropertyChanged}"
                                        DisplayMemberPath="Name" SelectedValuePath="Id"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>元請 :</Label>
                                    <TextBlock x:Name="ContractorView" Text="{Binding Text, ElementName=Contractor}"/>
                                    <ComboBox x:Name="Contractor" SelectedValue="{Binding ContractorId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                        Text="{Binding ContractorName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                        ItemsSource="{Binding DataContext.Contractors, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}, UpdateSourceTrigger=PropertyChanged}"
                                        DisplayMemberPath="Name" SelectedValuePath="Id" IsEditable="True"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12">
                                    <Border Style="{StaticResource SeparatorBorderStyle}"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12">
                                    <Label>住所 :</Label>
                                    <TextBlock x:Name="AddressView" Text="{Binding Text, ElementName=Address}"/>
                                    <TextBox x:Name="Address" Text="{Binding Address, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="128"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>電話 :</Label>
                                    <TextBlock x:Name="PhoneNumberView" Text="{Binding Text, ElementName=PhoneNumber}"/>
                                    <TextBox x:Name="PhoneNumber" Text="{Binding PhoneNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="16"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>Fax :</Label>
                                    <TextBlock x:Name="FaxNumberView" Text="{Binding Text, ElementName=FaxNumber}"/>
                                    <TextBox x:Name="FaxNumber" Text="{Binding FaxNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="16"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>工期 :</Label>
                                    <TextBlock x:Name="FromDateView" Text="{Binding Text, ElementName=FromDate}"/>
                                    <DatePicker x:Name="FromDate" SelectedDate="{Binding FromDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>～</Label>
                                    <TextBlock x:Name="ToDateView" Text="{Binding Text, ElementName=ToDate}"/>
                                    <DatePicker x:Name="ToDate" SelectedDate="{Binding ToDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>種類 :</Label>
                                    <TextBlock x:Name="TypeView" Text="{Binding Text, ElementName=Type}"/>
                                    <ComboBox x:Name="Type" SelectedValue="{Binding Type, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                        ItemsSource="{Binding DataContext.Types, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}"
                                        DisplayMemberPath="Name" SelectedValuePath="Value"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>用途 :</Label>
                                    <TextBlock x:Name="UseView" Text="{Binding Text, ElementName=Use}"/>
                                    <ComboBox x:Name="Use" SelectedValue="{Binding Use, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                        ItemsSource="{Binding DataContext.Uses, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}"
                                        DisplayMemberPath="Name" SelectedValuePath="Value"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12">
                                    <Border Style="{StaticResource SeparatorBorderStyle}"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>受注額 :</Label>
                                    <TextBlock x:Name="FixedValueView" Text="{Binding FixedValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}"/>
                                    <TextBox x:Name="FixedValue" Text="{Binding FixedValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>見積額 :</Label>
                                    <TextBlock x:Name="QuotedValueView" Text="{Binding QuotedValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}"/>
                                    <TextBox x:Name="QuotedValue" Text="{Binding QuotedValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12">
                                    <Border Style="{StaticResource SeparatorBorderStyle}"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12">
                                    <Label>備考 :</Label>
                                    <TextBlock x:Name="RemarksView" Text="{Binding Text, ElementName=Remarks}"/>
                                    <TextBox x:Name="Remarks" Text="{Binding Remarks, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="64"/>
                                </DockPanel>
                            </ResponsiveGrid>
                        </StackPanel>
                        <DataTemplate.Triggers>
                            <Trigger Property="DataContext" Value="{x:Null}">
                                <Setter Property="Visibility" TargetName="Content" Value="Collapsed"/>
                            </Trigger>
                            <DataTrigger Binding="{Binding DataContext.IsEditing, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}" Value="False">
                                <Setter Property="Visibility" TargetName="Id" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Project" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="User" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="SalesUser" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Name" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="DesignOffice" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Orderer" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Contractor" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Address" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="PhoneNumber" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="FaxNumber" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="FromDate" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="ToDate" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Type" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Use" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="FixedValue" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="QuotedValue" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Remarks" Value="Collapsed"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding DataContext.IsEditing, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}" Value="True">
                                <Setter Property="Visibility" TargetName="IdView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="ProjectView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="UserView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="SalesUserView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="NameView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="DesignOfficeView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="OrdererView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="ContractorView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="AddressView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="PhoneNumberView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="FaxNumberView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="FromDateView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="ToDateView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="TypeView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="UseView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="FixedValueView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="QuotedValueView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="RemarksView" Value="Collapsed"/>
                            </DataTrigger>
                            <MultiDataTrigger>
                                <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding DataContext.IsEditing, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}" Value="True"/>
                                    <Condition Binding="{Binding IsNew}" Value="False"/>
                                </MultiDataTrigger.Conditions>
                                <Setter Property="Visibility" TargetName="IdView" Value="Visible"/>
                                <Setter Property="Visibility" TargetName="ProjectView" Value="Visible"/>
                                <Setter Property="Visibility" TargetName="Id" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Project" Value="Collapsed"/>
                            </MultiDataTrigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>
                </ContentControl.ContentTemplate>
            </ContentControl>
        </Border>
    </Grid>
</UserControl>
ToDo: Navigation
<RibbonWindow
    x:Class="Tact.Windows.Views.Navigation"
    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"
    xmlns:Interactivity="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:Prism="http://prismlibrary.com/"
    xmlns:Commands="clr-namespace:Tact.Windows.Commands"
    xmlns:Regions="clr-namespace:Tact.Windows.Regions"
    xmlns:Views="clr-namespace:Tact.Windows.Views"
    xmlns:Models="clr-namespace:Tact.Windows.ViewModels"
    d:DataContext="{d:DesignInstance {x:Type Models:NavigationViewModel}, IsDesignTimeCreatable=True}"
    d:DesignWidth="1280" d:DesignHeight="720"
    Icon="/Icon.ico"
    Title="Tact"
    FontFamily="Segoe UI, Meiryo UI"
    FontSize="12"
    Style="{DynamicResource ResourceKey={x:Type RibbonWindow}}"
    Width="1280" Height="720"
    WindowStartupLocation="CenterScreen"
    Prism:ViewModelLocator.AutoWireViewModel="True">
    <Interactivity:Interaction.Triggers>
        <Interactivity:EventTrigger EventName="Loaded">
            <Interactivity:InvokeCommandAction Command="{Binding Commands.Execute}" CommandParameter="{x:Static Regions:NavigationContents.Login}"/>
        </Interactivity:EventTrigger>
        <Prism:InteractionRequestTrigger SourceObject="{Binding Requests.Login, Mode=OneWay}">
            <Prism:PopupWindowAction
                IsModal="True"
                CenterOverAssociatedObject="True"
                WindowStyle="{StaticResource DialogStyle}">
                <Prism:PopupWindowAction.WindowContent>
                    <Views:Login/>
                </Prism:PopupWindowAction.WindowContent>
            </Prism:PopupWindowAction>
        </Prism:InteractionRequestTrigger>
        <Prism:InteractionRequestTrigger SourceObject="{Binding Requests.Notification, Mode=OneWay}">
            <Prism:PopupWindowAction
                IsModal="True"
                CenterOverAssociatedObject="True"
                WindowStyle="{StaticResource DialogStyle}">
                <Prism:PopupWindowAction.WindowContent>
                    <Views:Notification/>
                </Prism:PopupWindowAction.WindowContent>
            </Prism:PopupWindowAction>
        </Prism:InteractionRequestTrigger>
    </Interactivity:Interaction.Triggers>
    <DockPanel>
        <Ribbon DockPanel.Dock="Top" Prism:RegionManager.RegionName="{x:Static Regions:NavigationRegions.Ribbon}" KeyboardNavigation.TabNavigation="Continue">
            <Ribbon.ApplicationMenu>
                <RibbonApplicationMenu Label="ファイル" KeyTip="F" Visibility="Collapsed"/>
            </Ribbon.ApplicationMenu>
            <Ribbon.ContextualTabGroups>
                <RibbonContextualTabGroup Header="{Binding Title}" Visibility="Visible" Foreground="#FFB1D6F0" Background="#FF015C9F" BorderBrush="Red"/>
            </Ribbon.ContextualTabGroups>
            <RibbonTab Header="ホーム" KeyTip="H">
                <RibbonGroup Header="見積管理">
                    <RibbonButton Label="見積" LargeImageSource="/Resources/Images/Project.png"
                        Command="{Binding Commands.Execute}" CommandParameter="{x:Static Regions:NavigationContents.Project}"/>
                </RibbonGroup>
                <RibbonGroup Header="工事管理">
                    <RibbonButton Label="工事報告" LargeImageSource="/Resources/Images/Order.png"
                        Command="{Binding Commands.Execute}" CommandParameter="{x:Static Regions:NavigationContents.Order}"/>
                </RibbonGroup>
                <RibbonGroup Header="工事台帳">
                    <RibbonButton Label="工事台帳" LargeImageSource="/Resources/Images/Print.png"/>
                </RibbonGroup>
                <RibbonGroup Header="完成工事管理">
                    <RibbonButton Label="完成工事計上" LargeImageSource="/Resources/Images/Performance.png"
                        Command="{Binding Commands.Execute}" CommandParameter="{x:Static Regions:NavigationContents.Performance}"/>
                    <RibbonButton Label="完成工事計上明細" SmallImageSource="/Resources/Images/Print.png"/>
                    <RibbonButton Label="完成工事未収入金" SmallImageSource="/Resources/Images/Print.png"/>
                    <RibbonButton Label="未成工事支出金明細" SmallImageSource="/Resources/Images/Print.png"/>
                </RibbonGroup>
                <RibbonGroup Header="経費管理">
                    <RibbonButton Label="外注費" LargeImageSource="/Resources/Images/OutsourcingCost.png"
                        Command="{Binding Commands.Execute}" CommandParameter="{x:Static Regions:NavigationContents.OutsourcingCost}"/>
                    <RibbonButton Label="材料費" LargeImageSource="/Resources/Images/MaterialCost.png"
                        Command="{Binding Commands.Execute}" CommandParameter="{x:Static Regions:NavigationContents.MaterialCost}"/>
                    <RibbonButton Label="現場経費" LargeImageSource="/Resources/Images/FieldCost.png"
                        Command="{Binding Commands.Execute}" CommandParameter="{x:Static Regions:NavigationContents.FieldCost}"/>
                    <RibbonButton Label="直用工経費" LargeImageSource="/Resources/Images/DirectCost.png"
                        Command="{Binding Commands.Execute}" CommandParameter="{x:Static Regions:NavigationContents.DirectCost}"/>
                    <RibbonButton Label="労務費" LargeImageSource="/Resources/Images/Deduction.png"
                        Command="{Binding Commands.Execute}" CommandParameter="{x:Static Regions:NavigationContents.Deduction}"/>
                </RibbonGroup>
                <RibbonGroup Header="入金管理">
                    <RibbonButton Label="請求" LargeImageSource="/Resources/Images/Invoice.png"
                        Command="{Binding Commands.Execute}" CommandParameter="{x:Static Regions:NavigationContents.Invoice}"/>
                    <RibbonButton Label="入金" LargeImageSource="/Resources/Images/Receipt.png"
                        Command="{Binding Commands.Execute}" CommandParameter="{x:Static Regions:NavigationContents.Receipt}"/>
                </RibbonGroup>
            </RibbonTab>
            <RibbonTab Header="マスタ" KeyTip="M">
                <RibbonGroup Header="取引先">
                    <RibbonButton
                        Label="受注先" LargeImageSource="/Resources/Images/Orderer.png"
                        Command="{Binding Commands.Execute}" CommandParameter="{x:Static Regions:NavigationContents.Orderer}"/>
                    <RibbonButton
                        Label="外注先" LargeImageSource="/Resources/Images/Outsourcee.png"
                        Command="{Binding Commands.Execute}" CommandParameter="{x:Static Regions:NavigationContents.Outsourcee}"/>
                    <RibbonButton
                        Label="材料・経費" LargeImageSource="/Resources/Images/OtherCustomer.png"
                        Command="{Binding Commands.Execute}" CommandParameter="{x:Static Regions:NavigationContents.OtherCustomer}"/>
                </RibbonGroup>
                <RibbonGroup Header="社員">
                    <RibbonButton Label="社員" LargeImageSource="/Resources/Images/User.png"
                        Command="{Binding Commands.Execute}" CommandParameter="{x:Static Regions:NavigationContents.User}"/>
                </RibbonGroup>
                <RibbonGroup Header="月締処理">
                    <RibbonButton Label="月締処理" LargeImageSource="/Resources/Images/Setting.png"
                        Command="{Binding Commands.Execute}" CommandParameter="{x:Static Regions:NavigationContents.Setting}"/>
                </RibbonGroup>
            </RibbonTab>
        </Ribbon>
        <StatusBar DockPanel.Dock="Bottom">
            <TextBlock Text="{Binding Status.Value}"/>
        </StatusBar>
        <Border>
            <ContentControl Prism:RegionManager.RegionName="{x:Static Regions:NavigationRegions.Content}" Focusable="False"/>
        </Border>
    </DockPanel>
</RibbonWindow>

ToDo: Deductions
<UserControl
    x:Class="Tact.Windows.Views.Deductions"
    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"
    xmlns:Interactivity="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:Prism="http://prismlibrary.com/"
    xmlns:Commands="clr-namespace:Tact.Windows.Commands"
    xmlns:Views="clr-namespace:Tact.Windows.Views"
    xmlns:Models="clr-namespace:Tact.Windows.ViewModels"
    d:DataContext="{d:DesignInstance {x:Type Models:DeductionsViewModel}, IsDesignTimeCreatable=True}"
    d:DesignWidth="1280" d:DesignHeight="720"
    Prism:ViewModelLocator.AutoWireViewModel="True">
    <Grid Style="{StaticResource ContentGridStyle}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="256"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Border Grid.Column="0">
            <ResponsiveGrid>
                <ResponsiveGrid.Resources>
                    <Style TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}">
                        <Setter Property="Width" Value="64"/>
                    </Style>
                </ResponsiveGrid.Resources>
                <DockPanel ResponsiveGrid.ColumnSpan="12" LastChildFill="False">
                    <Label>年月 :</Label>
                    <TextBlock x:Name="Year" Text="{Binding Year, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                    <TextBlock>年</TextBlock>
                    <TextBlock x:Name="Month" Text="{Binding Month, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                    <TextBlock>月</TextBlock>
                </DockPanel>
                <DockPanel ResponsiveGrid.ColumnSpan="12">
                    <Label>支払区分 :</Label>
                    <ComboBox x:Name="Type" IsEnabled="{Binding IsReadOnly}"
                        ItemsSource="{Binding Types}"
                        DisplayMemberPath="Value" SelectedValuePath="Key"/>
                </DockPanel>
                <DockPanel ResponsiveGrid.ColumnSpan="12">
                    <Label>支払先 :</Label>
                    <ComboBox x:Name="Customer" IsEnabled="{Binding IsReadOnly}"
                        ItemsSource="{Binding Customers}"
                        DisplayMemberPath="Name" SelectedValuePath="Id"/>
                </DockPanel>
                <DockPanel ResponsiveGrid.ColumnSpan="12">
                    <Label>支払日 :</Label>
                    <DatePicker x:Name="Date" SelectedDate="{Binding Date, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                </DockPanel>
                <DockPanel ResponsiveGrid.ColumnSpan="12">
                    <Label>期間 :</Label>
                    <DatePicker x:Name="FromDate" SelectedDate="{Binding FromDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                </DockPanel>
                <DockPanel ResponsiveGrid.ColumnSpan="12">
                    <Label HorizontalContentAlignment="Right" Padding="3,3,6,3">～</Label>
                    <DatePicker x:Name="ToDate" SelectedDate="{Binding ToDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                </DockPanel>
            </ResponsiveGrid>
        </Border>
        <GridSplitter Grid.Column="1" Style="{StaticResource VerticalSplitterStyle}"/>
        <Border Grid.Column="2" Style="{StaticResource ContentBorderStyle}">
            <DockPanel>
                <DockPanel.Resources>
                    <BooleanToOppositeBooleanConverter x:Key="BooleanToOppositeBooleanConverter"/>
                    <FrameworkElement x:Key="ToollVisibility" DataContext="{Binding IsEditing, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"/>
                </DockPanel.Resources>
                <ContentControl Visibility="Collapsed" Content="{StaticResource ToollVisibility}"/>
                <DockPanel DockPanel.Dock="Top" Height="256" Margin="0,0,0,6">
                    <DataGrid DockPanel.Dock="Bottom" ItemsSource="{Binding CostTotal}" Style="{StaticResource FooterDataGridStyle}">
                        <DataGrid.Columns>
                            <DataGridCustomColumn Width="256">
                                <DataGridCustomColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="支払合計" Style="{StaticResource CellStyle}" HorizontalAlignment="Center"/>
                                    </DataTemplate>
                                </DataGridCustomColumn.CellTemplate>
                            </DataGridCustomColumn>
                            <DataGridCustomColumn Width="96">
                                <DataGridCustomColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Value, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}" Style="{StaticResource RightCellStyle}"/>
                                    </DataTemplate>
                                </DataGridCustomColumn.CellTemplate>
                            </DataGridCustomColumn>
                        </DataGrid.Columns>
                    </DataGrid>
                    <DataGrid ItemsSource="{Binding Costs}" Focusable="False" IsReadOnly="True" SelectionMode="Single">
                        <DataGrid.Columns>
                            <DataGridCustomColumn Header="支払明細" Width="256">
                                <DataGridCustomColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Order.Name, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource CellStyle}"/>
                                    </DataTemplate>
                                </DataGridCustomColumn.CellTemplate>
                            </DataGridCustomColumn>
                            <DataGridCustomColumn Header="支払金額" Width="96">
                                <DataGridCustomColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Value, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}" Style="{StaticResource RightCellStyle}"/>
                                    </DataTemplate>
                                </DataGridCustomColumn.CellTemplate>
                            </DataGridCustomColumn>
                        </DataGrid.Columns>
                    </DataGrid>
                </DockPanel>
                <DockPanel DockPanel.Dock="Top">
                    <ToolBarTray DockPanel.Dock="Left" Background="Transparent"
                        Visibility="{Binding DataContext, Source={StaticResource ToollVisibility}, Converter={StaticResource BooleanToVisibilityConverter}}">
                        <ToolBar Background="White">
                            <Button Command="{x:Static Commands:CollectionCompositeCommands.Add}" ToolTip="追加">
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="/Resources/Images/New.png" Width="16" Height="16" />
                                    <TextBlock Margin="3,0,0,0">追加</TextBlock>
                                </StackPanel>
                            </Button>
                            <Separator/>
                            <Button Command="{x:Static Commands:CollectionCompositeCommands.Remove}" ToolTip="削除">
                                <StackPanel Orientation="Horizontal">
                                    <Image Source="/Resources/Images/Cancel.png" Width="16" Height="16" />
                                    <TextBlock Margin="3,0,0,0">削除</TextBlock>
                                </StackPanel>
                            </Button>
                        </ToolBar>
                    </ToolBarTray>
                </DockPanel>
                <DataGrid DockPanel.Dock="Bottom" ItemsSource="{Binding Total}" Style="{StaticResource SummaryDataGridStyle}" Margin="0,6,0,0">
                    <DataGrid.Columns>
                        <DataGridCustomColumn Width="256">
                            <DataGridCustomColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="差引支払合計" Style="{StaticResource CellStyle}" HorizontalAlignment="Center"/>
                                </DataTemplate>
                            </DataGridCustomColumn.CellTemplate>
                        </DataGridCustomColumn>
                        <DataGridCustomColumn Width="96">
                            <DataGridCustomColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding Value, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}" Style="{StaticResource RightCellStyle}"/>
                                </DataTemplate>
                            </DataGridCustomColumn.CellTemplate>
                        </DataGridCustomColumn>
                    </DataGrid.Columns>
                </DataGrid>
                <DockPanel>
                    <DataGrid DockPanel.Dock="Bottom" ItemsSource="{Binding DeductionTotal}" Style="{StaticResource FooterDataGridStyle}">
                        <DataGrid.Columns>
                            <DataGridCustomColumn Width="256">
                                <DataGridCustomColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="控除合計" Style="{StaticResource CellStyle}" HorizontalAlignment="Center"/>
                                    </DataTemplate>
                                </DataGridCustomColumn.CellTemplate>
                            </DataGridCustomColumn>
                            <DataGridCustomColumn Width="96">
                                <DataGridCustomColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Value, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}" Style="{StaticResource RightCellStyle}"/>
                                    </DataTemplate>
                                </DataGridCustomColumn.CellTemplate>
                            </DataGridCustomColumn>
                        </DataGrid.Columns>
                    </DataGrid>
                    <DataGrid x:Name="Requires" DockPanel.Dock="Bottom" ItemsSource="{Binding Requires}" Style="{StaticResource FixedDataGridStyle}" IsReadOnly="{Binding IsReadOnly}">
                        <Interactivity:Interaction.Behaviors>
                            <Interactivity:DataGridBehavior/>
                        </Interactivity:Interaction.Behaviors>
                        <DataGrid.Columns>
                            <DataGridCustomColumn Header="控除明細" Width="256" IsReadOnly="True">
                                <DataGridCustomColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Name, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource CellStyle}"/>
                                    </DataTemplate>
                                </DataGridCustomColumn.CellTemplate>
                            </DataGridCustomColumn>
                            <DataGridCustomColumn Header="控除金額" Width="96">
                                <DataGridCustomColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Value, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}" Style="{StaticResource RightCellStyle}"/>
                                    </DataTemplate>
                                </DataGridCustomColumn.CellTemplate>
                                <DataGridCustomColumn.CellEditingTemplate>
                                    <DataTemplate>
                                        <TextBox Text="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource TextRightCellStyle}"/>
                                    </DataTemplate>
                                </DataGridCustomColumn.CellEditingTemplate>
                            </DataGridCustomColumn>
                        </DataGrid.Columns>
                    </DataGrid>
                    <DataGrid x:Name="Source" ItemsSource="{Binding Source}" IsReadOnly="{Binding IsReadOnly}" SelectionMode="Single">
                        <Interactivity:Interaction.Behaviors>
                            <Interactivity:DataGridBehavior/>
                        </Interactivity:Interaction.Behaviors>
                        <DataGrid.Columns>
                            <DataGridCustomColumn Header="控除明細" Width="256">
                                <DataGridCustomColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Name, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource CellStyle}"/>
                                    </DataTemplate>
                                </DataGridCustomColumn.CellTemplate>
                                <DataGridCustomColumn.CellEditingTemplate>
                                    <DataTemplate>
                                        <TextBox Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource TextCellStyle}"/>
                                    </DataTemplate>
                                </DataGridCustomColumn.CellEditingTemplate>
                            </DataGridCustomColumn>
                            <DataGridCustomColumn Header="控除金額" Width="96">
                                <DataGridCustomColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Value, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat={}{0:N0}}" Style="{StaticResource RightCellStyle}"/>
                                    </DataTemplate>
                                </DataGridCustomColumn.CellTemplate>
                                <DataGridCustomColumn.CellEditingTemplate>
                                    <DataTemplate>
                                        <TextBox Text="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource TextRightCellStyle}"/>
                                    </DataTemplate>
                                </DataGridCustomColumn.CellEditingTemplate>
                            </DataGridCustomColumn>
                        </DataGrid.Columns>
                    </DataGrid>
                </DockPanel>
            </DockPanel>
        </Border>
    </Grid>
</UserControl>
ToDo: Customers
<UserControl
    x:Class="Tact.Windows.Views.Customers"
    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"
    xmlns:Interactivity="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:Prism="http://prismlibrary.com/"
    xmlns:Views="clr-namespace:Tact.Windows.Views"
    xmlns:Models="clr-namespace:Tact.Windows.ViewModels"
    d:DataContext="{d:DesignInstance {x:Type Models:CustomersViewModel}, IsDesignTimeCreatable=True}"
    d:DesignWidth="1280" d:DesignHeight="720"
    Prism:ViewModelLocator.AutoWireViewModel="True">
    <Grid Style="{StaticResource ContentGridStyle}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="256"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Border Grid.Column="0">
            <DockPanel>
                <ResponsiveGrid DockPanel.Dock="Top">
                    <DockPanel ResponsiveGrid.ColumnSpan="12">
                        <TextBox x:Name="Filter" Text="{Binding Filter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding IsReadOnly}"/>
                    </DockPanel>
                </ResponsiveGrid>
                <ListView ItemsSource="{Binding Source}">
                    <Interactivity:Interaction.Behaviors>
                        <Interactivity:ListViewAutoResizeBehavior/>
                        <Interactivity:ListViewAutoScrollBehavior/>
                    </Interactivity:Interaction.Behaviors>
                    <ListView.Resources>
                        <DataTemplate x:Key="Id" DataType="{x:Type Models:Customer}">
                            <TextBlock Text="{Binding Id}" Style="{StaticResource AsideStyle}"/>
                        </DataTemplate>
                        <DataTemplate x:Key="Name" DataType="{x:Type Models:Customer}">
                            <TextBlock Text="{Binding Name}"/>
                        </DataTemplate>
                        <Style x:Key="Container" TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource {x:Type ListViewItem}}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type ListViewItem}">
                                        <Border Name="Border" Style="{StaticResource ItemBorderStyle}">
                                            <StackPanel>
                                                <GridViewRowPresenter Content="{TemplateBinding Content}" Columns="{TemplateBinding GridView.ColumnCollection}"/>
                                                <TextBlock Text="{Binding Address}" Style="{StaticResource AsideIndentStyle}"/>
                                            </StackPanel>
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsSelected" Value="True">
                                                <Setter TargetName="Border" Property="Background" Value="{DynamicResource HighlightBackground}"/>
                                                <Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource ActiveBorder}"/>
                                                <Setter TargetName="Border" Property="BorderThickness" Value="3,0,0,0"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ListView.Resources>
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Header="ID" CellTemplate="{StaticResource Id}"/>
                            <GridViewColumn Header="会社名/氏名" CellTemplate="{StaticResource Name}"/>
                        </GridView>
                    </ListView.View>
                    <ListView.ItemContainerStyle>
                        <Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource Container}"/>
                    </ListView.ItemContainerStyle>
                </ListView>
            </DockPanel>
        </Border>
        <GridSplitter Grid.Column="1" Style="{StaticResource VerticalSplitterStyle}"/>
        <Border Grid.Column="2" Style="{StaticResource ContentBorderStyle}">
            <ContentControl Content="{Binding Current}">
                <ContentControl.ContentTemplate>
                    <DataTemplate DataType="{x:Type Models:Customer}">
                        <StackPanel x:Name="Content" Orientation="Vertical">
                            <Interactivity:Interaction.Behaviors>
                                <Interactivity:FocusBehavior/>
                            </Interactivity:Interaction.Behaviors>
                            <ResponsiveGrid>
                                <ResponsiveGrid.Resources>
                                    <Style TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}">
                                        <Setter Property="Width" Value="64"/>
                                    </Style>
                                </ResponsiveGrid.Resources>
                                <DockPanel x:Name="IdView" ResponsiveGrid.ColumnSpan="12" LastChildFill="False">
                                    <Label>ID :</Label>
                                    <TextBlock Text="{Binding Id, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                                </DockPanel>
                                <DockPanel x:Name="Id" ResponsiveGrid.ColumnSpan="12" LastChildFill="False">
                                    <Label Width="Auto">相手先区分 :</Label>
                                    <ComboBox SelectedValue="{Binding Type, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="128"
                                        ItemsSource="{Binding DataContext.Types, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}"
                                        DisplayMemberPath="Value" SelectedValuePath="Key"/>
                                    <Label Width="Auto">頭文字 :</Label>
                                    <TextBox Text="{Binding Initial, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="32" MaxLength="1"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="6">
                                    <Label Width="Auto">会社名/氏名 :</Label>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="6">
                                    <Label Width="Auto">代表者氏名 :</Label>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="6">
                                    <TextBlock x:Name="NameKanaView" Text="{Binding Text, ElementName=NameKana}"/>
                                    <TextBox x:Name="NameKana" Text="{Binding NameKana, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="64"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="6">
                                    <TextBlock x:Name="RepresentativeKanaView" Text="{Binding Text, ElementName=RepresentativeKana}"/>
                                    <TextBox x:Name="RepresentativeKana" Text="{Binding RepresentativeKana, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="64"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="6">
                                    <TextBlock x:Name="NameView" Text="{Binding Text, ElementName=Name}"/>
                                    <TextBox x:Name="Name" Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="64"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="6">
                                    <TextBlock x:Name="RepresentativeView" Text="{Binding Text, ElementName=Representative}"/>
                                    <TextBox x:Name="Representative" Text="{Binding Representative, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="64"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12">
                                    <Border Style="{StaticResource SeparatorBorderStyle}"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6" LastChildFill="False">
                                    <Label>宛名 :</Label>
                                    <TextBlock x:Name="SuffixView" Text="{Binding Text, ElementName=Suffix}"/>
                                    <ComboBox x:Name="Suffix" Text="{Binding Suffix, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="64"
                                        ItemsSource="{Binding DataContext.Suffixes, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}"
                                        DisplayMemberPath="Name" SelectedValuePath="Value" IsEditable="True"/>
                                </DockPanel>
                                <DockPanel x:Name="BusinessBlock" ResponsiveGrid.ColumnSpan="12,6" Visibility="Hidden">
                                    <Label>業種 :</Label>
                                    <TextBlock x:Name="BusinessView" Text="{Binding Text, ElementName=Business}"/>
                                    <TextBox x:Name="Business" Text="{Binding Business, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="64"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12">
                                    <Label>住所 :</Label>
                                    <TextBlock x:Name="PostCodeView" Text="{Binding Text, ElementName=PostCode}"/>
                                    <TextBox x:Name="PostCode" Text="{Binding PostCode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Width="64" MaxLength="7"/>
                                    <TextBlock x:Name="AddressView" Text="{Binding Text, ElementName=Address}"/>
                                    <TextBox x:Name="Address" Text="{Binding Address, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="128"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>電話 :</Label>
                                    <TextBlock x:Name="PhoneNumberView" Text="{Binding Text, ElementName=PhoneNumber}"/>
                                    <TextBox x:Name="PhoneNumber" Text="{Binding PhoneNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="16"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12,6">
                                    <Label>Fax :</Label>
                                    <TextBlock x:Name="FaxNumberView" Text="{Binding Text, ElementName=FaxNumber}"/>
                                    <TextBox x:Name="FaxNumber" Text="{Binding FaxNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="16"/>
                                </DockPanel>
                            </ResponsiveGrid>
                            <ResponsiveGrid x:Name="Receipt" Visibility="Collapsed">
                                <ResponsiveGrid.Resources>
                                    <Style TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}">
                                        <Setter Property="Width" Value="64"/>
                                    </Style>
                                </ResponsiveGrid.Resources>
                                <DockPanel ResponsiveGrid.ColumnSpan="12">
                                    <Border Style="{StaticResource SeparatorBorderStyle}"/>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12" LastChildFill="False">
                                    <Label>締切日 :</Label>
                                    <TextBlock x:Name="ClosingDayView" Text="{Binding Text, ElementName=ClosingDay}"/>
                                    <TextBox x:Name="ClosingDay" Text="{Binding ClosingDay, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right" Width="32" MaxLength="2"/>
                                    <TextBlock>日</TextBlock>
                                    <Label Width="Auto">請求書到着締切日 :</Label>
                                    <TextBlock x:Name="InvoiceDeadlineView" Text="{Binding Text, ElementName=InvoiceDeadline}"/>
                                    <TextBox x:Name="InvoiceDeadline" Text="{Binding InvoiceDeadline, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right" Width="32" MaxLength="2"/>
                                    <TextBlock>日</TextBlock>
                                    <Label Width="Auto">入金日 :</Label>
                                    <TextBlock x:Name="ReceiptMonthView" Text="{Binding Text, ElementName=ReceiptMonth}"/>
                                    <TextBox x:Name="ReceiptMonth" Text="{Binding ReceiptMonth, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right" Width="32" MaxLength="16"/>
                                    <TextBlock>月</TextBlock>
                                    <TextBlock x:Name="ReceiptDayView" Text="{Binding Text, ElementName=ReceiptDay}"/>
                                    <TextBox x:Name="ReceiptDay" Text="{Binding ReceiptDay, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right" Width="32" MaxLength="2"/>
                                    <TextBlock>日</TextBlock>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12" LastChildFill="False">
                                    <Label>現金 :</Label>
                                    <TextBlock x:Name="CashRateView" Text="{Binding Text, ElementName=CashRate}"/>
                                    <TextBox x:Name="CashRate" Text="{Binding CashRate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right" Width="32" MaxLength="3"/>
                                    <TextBlock>%</TextBlock>
                                    <Label Width="Auto">手形 :</Label>
                                    <TextBlock x:Name="BillRateView" Text="{Binding Text, ElementName=BillRate}"/>
                                    <TextBox x:Name="BillRate" Text="{Binding BillRate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right" Width="32" MaxLength="3"/>
                                    <TextBlock>%</TextBlock>
                                    <TextBlock>(</TextBlock>
                                    <Label Width="Auto">サイト :</Label>
                                    <TextBlock x:Name="SightView" Text="{Binding Text, ElementName=Sight}"/>
                                    <TextBox x:Name="Sight" Text="{Binding Sight, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right" Width="32" MaxLength="2"/>
                                    <TextBlock>日)</TextBlock>
                                </DockPanel>
                                <DockPanel ResponsiveGrid.ColumnSpan="12">
                                    <Label>保留金 :</Label>
                                    <CheckBox x:Name="HasRetentionMoney" IsChecked="{Binding HasRetentionMoney, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                                    <TextBlock x:Name="RetentionMoneyCommentView" Text="{Binding Text, ElementName=RetentionMoneyComment}"/>
                                    <TextBox x:Name="RetentionMoneyComment" Text="{Binding RetentionMoneyComment, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="64"/>
                                </DockPanel>
                            </ResponsiveGrid>
                        </StackPanel>
                        <DataTemplate.Triggers>
                            <Trigger Property="DataContext" Value="{x:Null}">
                                <Setter Property="Visibility" TargetName="Content" Value="Collapsed"/>
                            </Trigger>
                            <DataTrigger Binding="{Binding Type}" Value="Orderer">
                                <Setter Property="Visibility" TargetName="Receipt" Value="Visible"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding Type}" Value="Painting">
                                <Setter Property="Visibility" TargetName="BusinessBlock" Value="Visible"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding Type}" Value="Outsourcee">
                                <Setter Property="Visibility" TargetName="BusinessBlock" Value="Visible"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding DataContext.IsEditing, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}" Value="False">
                                <Setter Property="Visibility" TargetName="Id" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="NameKana" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Name" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="RepresentativeKana" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Representative" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Suffix" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Business" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="PostCode" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Address" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="PhoneNumber" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="FaxNumber" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="ClosingDay" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="InvoiceDeadline" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="ReceiptMonth" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="ReceiptDay" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="CashRate" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="BillRate" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="Sight" Value="Collapsed"/>
                                <Setter Property="IsEnabled" TargetName="HasRetentionMoney" Value="False"/>
                                <Setter Property="Visibility" TargetName="RetentionMoneyComment" Value="Collapsed"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding DataContext.IsEditing, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}" Value="True">
                                <Setter Property="Visibility" TargetName="IdView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="NameKanaView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="NameView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="RepresentativeKanaView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="RepresentativeView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="SuffixView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="BusinessView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="PostCodeView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="AddressView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="PhoneNumberView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="FaxNumberView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="ClosingDayView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="InvoiceDeadlineView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="ReceiptMonthView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="ReceiptDayView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="CashRateView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="BillRateView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="SightView" Value="Collapsed"/>
                                <Setter Property="Visibility" TargetName="RetentionMoneyCommentView" Value="Collapsed"/>
                            </DataTrigger>
                            <MultiDataTrigger>
                                <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding DataContext.IsEditing, RelativeSource={RelativeSource AncestorType={x:Type ContentControl}}}" Value="True"/>
                                    <Condition Binding="{Binding IsNew}" Value="False"/>
                                </MultiDataTrigger.Conditions>
                                <Setter Property="Visibility" TargetName="IdView" Value="Visible"/>
                                <Setter Property="Visibility" TargetName="Id" Value="Collapsed"/>
                            </MultiDataTrigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>
                </ContentControl.ContentTemplate>
            </ContentControl>
        </Border>
    </Grid>
</UserControl>
Private Sub cmd_Print_Click()
'    Dim L_Joken As String

    On Error GoTo cmd_print_Click_Err

    '指定された担当者の明細のみ印刷するか確認
    Select Case CF_DspMsg(4, DG_Que_Msg006, Me.Caption)
        'はい
        Case vbYes
            G_Joken = "拠点コード = '" & cmb_kyoten & _
                        "' and 工事担当者コード = '" & cmb_ktanto & "'"
            DoCmd.OpenReport DG_Report014, acViewPreview, , G_Joken
            DoCmd.OpenReport DG_Report009, acViewPreview, , G_Joken
            DoCmd.OpenForm DG_Form037, acNormal, , , , , G_Joken

        'いいえ
        Case vbNo
            '全担当者の明細を印刷するか確認
            If CF_DspMsg(2, DG_Que_Msg007, Me.Caption) = vbCancel Then GoTo cmd_print_Click_End

            '全担当者の明細の印刷を実行
            G_Joken = "拠点コード = '" & cmb_kyoten & "'"

            DoCmd.OpenReport DG_Report014, acViewPreview, , G_Joken
            DoCmd.OpenReport DG_Report009, acViewPreview, , G_Joken
            DoCmd.OpenForm DG_Form037, acNormal, , , , , G_Joken

        'キャンセル
        Case vbCancel
            GoTo cmd_print_Click_End

    End Select

cmd_print_Click_End:
    Exit Sub

cmd_print_Click_Err:
    If Err.Number = 2501 Then       '印刷途中でキャンセルされた時のエラーは無視
    Else
        MsgBox Err.Description
    End If
    Resume cmd_print_Click_End
End Sub

Q003_03
SELECT T002_00.拠点コード, T002_00.工事番号, T002_00.工事担当者コード, Left([T003_00]![支払先コード],1) AS 支払先頭文字, Nz([支払年月],"0") AS 年月, Sum(T003_01.支払額) AS 支払金額, Sum(T003_01.直用工) AS 直用工
FROM (T002_00 INNER JOIN T003_00 ON (T002_00.工事番号 = T003_00.工事番号) AND (T002_00.拠点コード = T003_00.拠点コード)) LEFT JOIN T003_01 ON (T003_00.明細番号 = T003_01.明細番号) AND (T003_00.支払先コード = T003_01.支払先コード) AND (T003_00.工事番号 = T003_01.工事番号) AND (T003_00.拠点コード = T003_01.拠点コード)
GROUP BY T002_00.拠点コード, T002_00.工事番号, T002_00.工事担当者コード, Left([T003_00]![支払先コード],1), Nz([支払年月],"0")
HAVING (((Left([T003_00]![支払先コード],1))="2"));

Q003_04
SELECT T002_00.拠点コード, T002_00.工事番号, T002_00.工事担当者コード, Left([T003_00]![支払先コード],1) AS 支払先頭文字, Nz([支払年月],"0") AS 年月, Sum(T003_01.支払額) AS 支払金額, Sum(T003_01.直用工) AS 直用工
FROM (T002_00 INNER JOIN T003_00 ON (T002_00.工事番号 = T003_00.工事番号) AND (T002_00.拠点コード = T003_00.拠点コード)) LEFT JOIN T003_01 ON (T003_00.明細番号 = T003_01.明細番号) AND (T003_00.支払先コード = T003_01.支払先コード) AND (T003_00.工事番号 = T003_01.工事番号) AND (T003_00.拠点コード = T003_01.拠点コード)
GROUP BY T002_00.拠点コード, T002_00.工事番号, T002_00.工事担当者コード, Left([T003_00]![支払先コード],1), Nz([支払年月],"0")

F003_01
=DSum("[支払額]+[直用工]","T003_01","拠点コード='" & [txt_kyoten] & "' and 工事番号='" & [cmb_code] & "' and 支払先コード='" & [txt_siharai] & "' and 明細番号=" & Nz([txt_no],0) & " and 支払年月<'" & Format([Forms]![F003_01]![txt_year],"0000") & Format([Forms]![F003_01]![txt_month],"

R003_00(総括表)
=DSum("[Q003_03]!支払金額+[Q003_03]!直用工","[Q003_03]","[Q003_03]![拠点コード]='" & [txt_kyoten] & "' and [Q003_03]![工事番号]='" & [txt_code] & "' and   [Q003_03]![年月]<>'" & Format([Forms]![F003_01]![txt_year],"0000") & Format([Forms]![F003_01]![txt_month],"00") & "'")
=DSum("[Q003_03]!支払金額+[Q003_03]!直用工","[Q003_03]","[Q003_03]![拠点コード]='" & [txt_kyoten] & "' and [Q003_03]![工事番号]='" & [txt_code] & "' and   [Q003_03]![年月]= '" & Format([Forms]![F003_01]![txt_year],"0000") & Format([Forms]![F003_01]![txt_month],"00") & "'")
=DSum("[Q003_04]!支払金額+[Q003_04]!直用工","[Q003_04]","[Q003_04]![拠点コード]='" & [txt_kyoten] & "' and [Q003_04]![工事番号]='" & [txt_code] & "' and   [Q003_04]![年月]<>'" & Format([Forms]![F003_01]![txt_year],"0000") & Format([Forms]![F003_01]![txt_month],"00") & "'")
=DSum("[Q003_04]!支払金額+[Q003_04]!直用工","[Q003_04]","[Q003_04]![拠点コード]='" & [txt_kyoten] & "' and [Q003_04]![工事番号]='" & [txt_code] & "' and   [Q003_04]![年月]= '" & Format([Forms]![F003_01]![txt_year],"0000") & Format([Forms]![F003_01]![txt_month],"00") & "'")

R003_01(明細)
=DSum("[T003_01]!支払額+[T003_01]!直用工","[T003_01]","[T003_01]![拠点コード]='" & [txt_kyoten] & "' and [T003_01]![工事番号]='" & [txt_code] & "' and [T003_01]![支払先コード]='" & [txt_siharai] & "' and [T003_01]![明細番号]=" & Nz([txt_no],0) & " and [T003_01]![支払年月]<>'" & Forma
=DSum("[T003_01]!支払額+[T003_01]!直用工","[T003_01]","[T003_01]![拠点コード]='" & [txt_kyoten] & "' and [T003_01]![工事番号]='" & [txt_code] & "' and [T003_01]![支払先コード]='" & [txt_siharai] & "' and [T003_01]![明細番号]=" & Nz([txt_no],0) & " and [T003_01]![支払年月]='" & Format