<Page x:Class="WSDDBBrowser.PgChartConfig"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:WSDDBBrowser"
      xmlns:conv="clr-namespace:WSDDBBrowser.Converter"
        xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
      xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
      mc:Ignorable="d" 
       d:DesignWidth="1024"
        d:DesignHeight="768"
      Title="PageChartConfig">
    <Page.Resources>
        <local:PgChartConfigViewModel_UnitTest x:Key="viewModel"/>

    </Page.Resources>
    <Grid d:DataContext="{StaticResource viewModel}">
        <ScrollViewer HorizontalScrollBarVisibility="Visible">

            <WrapPanel Orientation="Horizontal" TextBlock.Foreground="{DynamicResource TextBrush}" Margin="{StaticResource ControlMargin}">
                <StackPanel Orientation="Vertical">
                    <StackPanel Orientation="Horizontal">
                        <StackPanel Orientation="Vertical">
                            <StackPanel Orientation="Horizontal">
                                <iconPacks:PackIconMaterialLight VerticalAlignment="Center" Kind="FormatFloatLeft" Margin="{StaticResource ControlMargin}"/>
                                <TextBlock Text="基本产品信息" Style="{StaticResource h1}" Margin="{StaticResource ControlMargin}"/>
                            </StackPanel>
                            <StackPanel Orientation="Vertical" Margin="{StaticResource ControlMargin}" DataContext="{Binding Process}">
                                <StackPanel Orientation="Horizontal" Margin="1">
                                    <TextBlock Text="订单号:" Margin="0,0,10,0"/>
                                    <TextBlock FontSize="20" Text="{Binding cOrderNo}"/>
                                </StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="1">
                                    <TextBlock Text="项目号:" Margin="0,0,10,0"/>
                                    <TextBlock FontSize="20" Text="{Binding cProjectNo}"/>
                                </StackPanel>
                                <StackPanel Orientation="Horizontal" Margin="1">
                                    <TextBlock Text="工艺号:" Margin="0,0,10,0"/>
                                    <TextBlock FontSize="20" Text="{Binding cTechnologyNo}"/>
                                </StackPanel>
                            </StackPanel>
                            <DataGrid FontSize="13" Margin="{StaticResource ControlMargin}" AutoGenerateColumns="False" HeadersVisibility="All"
                                      ItemsSource="{Binding TechnologyItems}" RowHeaderWidth="20" SelectionUnit="FullRow" CanUserAddRows="False" CanUserDeleteRows="False">
                                <DataGrid.Columns>
                                    <DataGridTextColumn Binding="{Binding DeviceName}" IsReadOnly="True" Header="设备名称" />


                                    <DataGridTextColumn Binding="{Binding Target,StringFormat={}{0:F1}}" Header="目标值" />
                                    <DataGridTextColumn Binding="{Binding Tolerance,StringFormat={}{0:F1}}" Header="规格线" />
                                    <DataGridTextColumn Binding="{Binding Ctrlline,StringFormat={}{0:F1}}" Header="控制线" />
                                </DataGrid.Columns>
                                <DataGrid.Style>
                                    <Style BasedOn="{StaticResource MetroDataGrid}" TargetType="{x:Type DataGrid}">
                                        <Setter Property="AlternatingRowBackground" Value="{DynamicResource GrayBrush10}" />
                                    </Style>
                                </DataGrid.Style>
                                <DataGrid.RowValidationRules/>
                            </DataGrid>
                            <StackPanel Orientation="Horizontal">
                                <StackPanel Orientation="Vertical" Margin="{StaticResource ControlMargin}">
                                    <TextBlock Style="{StaticResource TitleStyle}">
                                        <Run Text="Y轴范围"/><Run Text="(规格线倍数)" FontSize="12"/>
                                    </TextBlock>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock Style="{StaticResource UnitStyle}" Text="±" VerticalAlignment="Bottom"/>
                                        <TextBox Style="{StaticResource ValueStyle}" Width="40" controls:TextBoxHelper.Watermark="Y轴范围" Text="{Binding YRangePercent,StringFormat={}{0:F1}}"/>
                                        <TextBlock Style="{StaticResource UnitStyle}" Text="倍" VerticalAlignment="Bottom"/>
                                    </StackPanel>

                                </StackPanel>
                                <StackPanel Orientation="Vertical" Margin="{StaticResource ControlMargin}">
                                    <TextBlock Style="{StaticResource TitleStyle}" Text="混合数" />
                                    <StackPanel Orientation="Horizontal">
                                        <TextBox Style="{StaticResource ValueStyle}" controls:TextBoxHelper.Watermark="混合数" Text="{Binding Mix}"/>
                                    </StackPanel>
                                </StackPanel>
                                <StackPanel Orientation="Vertical" Margin="{StaticResource ControlMargin}">
                                    <TextBlock Style="{StaticResource TitleStyle}" Text="直方图步长" />
                                    <StackPanel Orientation="Horizontal">

                                        <TextBox Style="{StaticResource ValueStyle}" controls:TextBoxHelper.Watermark="步长" Text="{Binding Step}"/>
                                    </StackPanel>
                                </StackPanel>
                            </StackPanel>

                        </StackPanel>
                        <Button VerticalAlignment="Top" HorizontalAlignment="Right" Style="{StaticResource AccentCircleButtonStyle}" Margin="{StaticResource ControlMargin}" Click="ButtonApplyClick">
                            <iconPacks:PackIconFontAwesome Width="40" Height="40"
                                               Kind="CheckCircleSolid" />
                        </Button>
                    </StackPanel>

                    <StackPanel Orientation="Vertical">
                        <StackPanel Orientation="Horizontal">
                            <iconPacks:PackIconMaterial VerticalAlignment="Center" Kind="ContentCut" Margin="{StaticResource ControlMargin}"/>
                            <TextBlock Text="分条" FontSize="24" Margin="{StaticResource ControlMargin}"/>
                            <StackPanel Orientation="Horizontal" Margin="{StaticResource ControlMargin}" VerticalAlignment="Bottom">
                                <TextBlock Style="{StaticResource TitleStyle}" Text="基材宽度:"/>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Style="{StaticResource ValueTextBlockStyle}" Text="{Binding FilmWidth}"/>
                                    <TextBlock Style="{StaticResource UnitStyle}" Text="mm"/>
                                </StackPanel>
                            </StackPanel>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <StackPanel Orientation="Vertical" Margin="{StaticResource ControlMargin}">
                                <TextBlock Style="{StaticResource TitleStyle}" Text="分切宽度" />
                                <StackPanel Orientation="Horizontal">
                                    <TextBox Style="{StaticResource ValueStyle}" Text="{Binding CuttingWidth}"/>
                                    <TextBlock Style="{StaticResource UnitStyle}" Text="mm" VerticalAlignment="Bottom"/>
                                </StackPanel>
                            </StackPanel>
                            <controls:ToggleSwitch Header="分切方式"
                                       Margin="{StaticResource ControlMargin}"
                                       IsChecked="{Binding IsCuttingCntEven}"
                                       OffLabel="双数"
                                       OnLabel="单数"
                                       Style="{StaticResource MahApps.Metro.Styles.ToggleSwitch.Win10}" />
                            <Button VerticalAlignment="Top" HorizontalAlignment="Right" Style="{StaticResource AccentCircleButtonStyle}" Margin="{StaticResource ControlMargin}" Click="ButtonCteateCuttingClick">
                                <iconPacks:PackIconMaterialDesign Width="20" Height="20"
                                               Kind="Create" />
                            </Button>
                        </StackPanel>

                        <DataGrid x:Name="MetroDataGrid"
                                      Margin="{StaticResource ControlMargin}"
                                    AutoGenerateColumns="False"
                                  HeadersVisibility="All"
                                  ItemsSource="{Binding CuttingMap}"
                                  RowHeaderWidth="20"
                                  SelectionUnit="FullRow"
                                      MinHeight="100" Width="200" HorizontalAlignment="Left"
                                      >
                            <DataGrid.Columns>
                                <controls:DataGridNumericUpDownColumn Binding="{Binding Begin}"
                                                          Header="开始"
                                                                  
                                                          Minimum="0"
                                                          StringFormat="{}{0:F0}" />
                                <controls:DataGridNumericUpDownColumn Binding="{Binding End}"
                                                          Header="结束"
                                                          Minimum="0"
                                                          StringFormat="{}{0:F0}" />
                            </DataGrid.Columns>
                            <DataGrid.Style>
                                <Style BasedOn="{StaticResource MetroDataGrid}" TargetType="{x:Type DataGrid}">
                                    <Setter Property="AlternatingRowBackground" Value="{DynamicResource GrayBrush10}" />
                                </Style>
                            </DataGrid.Style>
                        </DataGrid>
                    </StackPanel>
                </StackPanel>
                <StackPanel Orientation="Vertical" x:Name="sp_statistics">
                    <StackPanel Orientation="Vertical">
                        <StackPanel Orientation="Horizontal">
                            <iconPacks:PackIconMaterial VerticalAlignment="Center" Kind="FormatListNumbered" Margin="{StaticResource ControlMargin}"/>
                            <TextBlock Text="卷号表" FontSize="24" Margin="{StaticResource ControlMargin}"/>
                        </StackPanel>
                        <DataGrid FontSize="13" Margin="{StaticResource ControlMargin}" AutoGenerateColumns="False" HeadersVisibility="All"
                                      ItemsSource="{Binding Numbers}" RowHeaderWidth="20" SelectionUnit="FullRow" IsReadOnly="True">
                            <DataGrid.Columns>
                                <DataGridTextColumn Binding="{Binding cNumber}" Header="卷号" />
                                <DataGridTextColumn Binding="{Binding tBeginTime,StringFormat={}{0:HH:mm}}" Header="开始时间" />
                                <DataGridTextColumn Binding="{Binding tEndTime,StringFormat={}{0:H:mm}}" Header="结束时间" />
                                <DataGridTextColumn Binding="{Binding nBeginLen,StringFormat={}{0:F1}}" Header="开始位置" />
                                <DataGridTextColumn Binding="{Binding nEndLen,StringFormat={}{0:F1}}" Header="结束位置" />
                            </DataGrid.Columns>
                            <DataGrid.Style>
                                <Style BasedOn="{StaticResource MetroDataGrid}" TargetType="{x:Type DataGrid}">
                                    <Setter Property="AlternatingRowBackground" Value="{DynamicResource GrayBrush10}" />
                                </Style>
                            </DataGrid.Style>
                            <DataGrid.RowValidationRules/>
                        </DataGrid>


                    </StackPanel>
                    <StackPanel Orientation="Vertical">
                        <StackPanel Orientation="Horizontal">
                            <iconPacks:PackIconMaterial VerticalAlignment="Center" Kind="Calculator" Margin="{StaticResource ControlMargin}"/>
                            <TextBlock Text="统计" FontSize="24" Margin="{StaticResource ControlMargin}"/>
                        </StackPanel>
                        <DataGrid FontSize="13" Margin="{StaticResource ControlMargin}" AutoGenerateColumns="False" HeadersVisibility="All"
                                      ItemsSource="{Binding ScanDataItems}" RowHeaderWidth="20" SelectionUnit="FullRow" IsReadOnly="True">
                            <DataGrid.Columns>
                                <DataGridTextColumn Binding="{Binding DeviceName}" Header="设备名称" />
                                <DataGridTextColumn Binding="{Binding Average,StringFormat={}{0:F1}}" Header="平均值" />
                                <DataGridTextColumn Binding="{Binding Sigma3,StringFormat={}{0:F1}}" Header="3σ" />
                                <DataGridTextColumn Binding="{Binding USL,StringFormat={}{0:F1}}" Header="USL" />
                                <DataGridTextColumn Binding="{Binding LSL,StringFormat={}{0:F1}}" Header="LSL" />
                                <DataGridTextColumn Binding="{Binding CPK,StringFormat={}{0:F2}}" Header="CPK" />
                                <DataGridTextColumn Binding="{Binding TolerancePercent,StringFormat={}{0:P1}}" Header="规格线内" />
                                <DataGridTextColumn Binding="{Binding CtrllinePercent,StringFormat={}{0:P1}}" Header="控制线内" />
                            </DataGrid.Columns>
                            <DataGrid.Style>
                                <Style BasedOn="{StaticResource MetroDataGrid}" TargetType="{x:Type DataGrid}">
                                    <Setter Property="AlternatingRowBackground" Value="{DynamicResource GrayBrush10}" />
                                </Style>
                            </DataGrid.Style>
                            <DataGrid.RowValidationRules/>
                        </DataGrid>


                    </StackPanel>

                </StackPanel>
            </WrapPanel>
        </ScrollViewer>

    </Grid>
</Page>
