刘彬 3 godzin temu
rodzic
commit
e17ed04df2

+ 75 - 0
LocalhostMES/Enums/StationType.cs

@@ -0,0 +1,75 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Markup;
+
+namespace LocalhostMES.Enums
+{
+    public enum StationType
+    {
+        OP10,
+        OP20_1,
+        OP20_2,
+        OP30_1,
+        OP30_2,
+        OP40_1,
+        OP40_2,
+        OP50_1,
+        OP50_2,
+        OP60_1,
+        OP60_2,
+        OP70_1,
+        OP70_2,
+        OP80_1,
+        OP80_2
+
+    }
+
+    public class EnumBindingSourceExtension : MarkupExtension
+    {
+        private Type _enumType;
+        public Type EnumType
+        {
+            get => _enumType;
+            set
+            {
+                if ( value != _enumType )
+                {
+                    if ( null != value )
+                    {
+                        Type enumType = Nullable.GetUnderlyingType(value) ?? value;
+                        if ( !enumType.IsEnum )
+                            throw new ArgumentException("Type must be for an Enum.");
+                    }
+
+                    _enumType = value;
+                }
+            }
+        }
+
+        public EnumBindingSourceExtension() { }
+
+        public EnumBindingSourceExtension(Type enumType)
+        {
+            EnumType = enumType;
+        }
+
+        public override object ProvideValue(IServiceProvider serviceProvider)
+        {
+            if ( null == _enumType )
+                throw new InvalidOperationException("The EnumType must be specified.");
+
+            Type actualEnumType = Nullable.GetUnderlyingType(_enumType) ?? _enumType;
+            Array enumValues = Enum.GetValues(actualEnumType);
+
+            if ( actualEnumType == _enumType )
+                return enumValues;
+
+            Array tempArray = Array.CreateInstance(actualEnumType, enumValues.Length + 1);
+            enumValues.CopyTo(tempArray, 1);
+            return tempArray;
+        }
+    }
+}

+ 1 - 0
LocalhostMES/LocalhostMES.csproj

@@ -406,6 +406,7 @@
     <Compile Include="Core\LogHelper.cs" />
     <Compile Include="Core\TrayIconManager.cs" />
     <Compile Include="DataBase\DatabaseHelper.cs" />
+    <Compile Include="Enums\StationType.cs" />
     <Compile Include="Models\MesModel.cs" />
     <Compile Include="ViewModels\MainViewModel.cs" />
     <Compile Include="Views\MainView.xaml.cs">

+ 236 - 1
LocalhostMES/Views/MainView.xaml

@@ -5,6 +5,7 @@
         xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:local="clr-namespace:LocalhostMES.Views"
+        xmlns:enums="clr-namespace:LocalhostMES.Enums"
         xmlns:prism="http://prismlibrary.com/"
         prism:ViewModelLocator.AutoWireViewModel="True"
         mc:Ignorable="d"
@@ -58,7 +59,34 @@
             <Setter Property="AlternatingRowBackground"
                     Value="#F5F5F5" />
         </Style>
-    </Window.Resources>
+
+          
+
+            <Style TargetType="TextBox">
+                <Setter Property="Margin"
+                        Value="5" />
+                <Setter Property="VerticalContentAlignment"
+                        Value="Center" />
+            </Style>
+
+            <Style TargetType="ComboBox">
+                <Setter Property="Margin"
+                        Value="5" />
+                <Setter Property="VerticalContentAlignment"
+                        Value="Center" />
+            </Style>
+
+            <Style TargetType="Label">
+                <Setter Property="Margin"
+                        Value="5,5,2,5" />
+                <Setter Property="VerticalAlignment"
+                        Value="Center" />
+            </Style>
+
+            <DataTemplate x:Key="StationTypeTemplate">
+                <TextBlock Text="{Binding Path=FormulaType, Mode=OneWay}" />
+            </DataTemplate>
+        </Window.Resources>
     <b:Interaction.Triggers>
         <b:EventTrigger EventName="Loaded">
             <b:InvokeCommandAction Command="{Binding LoadedCommand}" />
@@ -279,6 +307,213 @@
                 </Grid>
             </TabItem>
 
+            <TabItem Header="SN管理">
+                <Grid Margin="10">
+                    <Grid.RowDefinitions>
+                        <RowDefinition Height="Auto" />
+                        <RowDefinition Height="Auto" />
+                        <RowDefinition Height="*" />
+                        <RowDefinition Height="Auto" />
+                    </Grid.RowDefinitions>
+
+                    <!-- 标题 -->
+                    <TextBlock Grid.Row="0"
+                               Text="关键件信息管理系统"
+                               FontSize="20"
+                               FontWeight="Bold"
+                               HorizontalAlignment="Center"
+                               Margin="0,0,0,15" />
+
+                    <!-- 添加区域 -->
+                    <Border Grid.Row="1"
+                            BorderBrush="#CCCCCC"
+                            BorderThickness="1"
+                            CornerRadius="5"
+                            Padding="10"
+                            Margin="0,0,0,10"
+                            Background="#F5F5F5">
+                        <Grid>
+                            <Grid.ColumnDefinitions>
+                                <ColumnDefinition Width="Auto" />
+                                <ColumnDefinition Width="*" />
+                                <ColumnDefinition Width="Auto" />
+                                <ColumnDefinition Width="*" />
+                                <ColumnDefinition Width="Auto" />
+                                <ColumnDefinition Width="80" />
+                            </Grid.ColumnDefinitions>
+                            <Grid.RowDefinitions>
+                                <RowDefinition Height="Auto" />
+                                <RowDefinition Height="Auto" />
+                            </Grid.RowDefinitions>
+
+                            <!-- 第一行 -->
+                            <Label Grid.Row="0"
+                                   Grid.Column="0">工位类型:</Label>
+                            <ComboBox Grid.Row="0"
+                                      Grid.Column="1"
+                                      ItemsSource="{Binding Source={ enums:EnumBindingSource {x:Type enums:StationType}}}"
+                                      SelectedItem="{Binding NewPart.FormulaType}" />
+
+                            <Label Grid.Row="0"
+                                   Grid.Column="2">关键件条码:</Label>
+                            <TextBox Grid.Row="0"
+                                     Grid.Column="3"
+                                     Text="{Binding NewPart.PartNum, UpdateSourceTrigger=PropertyChanged}" />
+
+                            <Label Grid.Row="0"
+                                   Grid.Column="4">数量:</Label>
+                            <TextBox Grid.Row="0"
+                                     Grid.Column="5"
+                                     Text="{Binding NewPart.PartQty, UpdateSourceTrigger=PropertyChanged}" />
+
+                            <!-- 第二行 -->
+                            <Label Grid.Row="1"
+                                   Grid.Column="0">物料代码:</Label>
+                            <TextBox Grid.Row="1"
+                                     Grid.Column="1"
+                                     Text="{Binding NewPart.MaterialCode, UpdateSourceTrigger=PropertyChanged}" />
+
+                            <Label Grid.Row="1"
+                                   Grid.Column="2">原条码:</Label>
+                            <TextBox Grid.Row="1"
+                                     Grid.Column="3"
+                                     Text="{Binding NewPart.OldPartNum, UpdateSourceTrigger=PropertyChanged}" />
+
+                            <Label Grid.Row="1"
+                                   Grid.Column="4">位置序号:</Label>
+                            <TextBox Grid.Row="1"
+                                     Grid.Column="5"
+                                     Text="{Binding NewPart.PositionNo, UpdateSourceTrigger=PropertyChanged}" />
+                        </Grid>
+                    </Border>
+
+                    <!-- 按钮区域 -->
+                    <StackPanel Grid.Row="1"
+                                Orientation="Horizontal"
+                                HorizontalAlignment="Right"
+                                Margin="0,10,0,0"
+                                VerticalAlignment="Bottom">
+                        <Button Content="添加"
+                                Command="{Binding AddCommand}"
+                                Background="#4CAF50"
+                                Foreground="White" />
+                        <Button Content="清空"
+                                Command="{Binding ClearCommand}"
+                                Background="#FF9800"
+                                Foreground="White" />
+                        <Button Content="批量删除"
+                                Command="{Binding DeleteSelectedCommand}"
+                                Background="#F44336"
+                                Foreground="White" />
+                    </StackPanel>
+
+                    <!-- 数据列表 -->
+                    <DataGrid Grid.Row="2"
+                              ItemsSource="{Binding PartInfos}"
+                              SelectedItem="{Binding SelectedPart}"
+                              SelectionMode="Extended"
+                              AutoGenerateColumns="False"
+                              CanUserAddRows="False"
+                              IsReadOnly="True"
+                              GridLinesVisibility="None"
+                              RowDetailsVisibilityMode="Collapsed"
+                              HeadersVisibility="Column"
+                              Margin="0,10,0,10">
+
+                        <DataGrid.Resources>
+                            <Style TargetType="DataGridRow">
+                                <Style.Triggers>
+                                    <Trigger Property="IsSelected"
+                                             Value="True">
+                                        <Setter Property="Background"
+                                                Value="#E3F2FD" />
+                                        <Setter Property="BorderBrush"
+                                                Value="#2196F3" />
+                                    </Trigger>
+                                </Style.Triggers>
+                            </Style>
+
+                            <Style TargetType="DataGridColumnHeader">
+                                <Setter Property="Background"
+                                        Value="#2196F3" />
+                                <Setter Property="Foreground"
+                                        Value="White" />
+                                <Setter Property="FontWeight"
+                                        Value="Bold" />
+                                <Setter Property="Padding"
+                                        Value="10,5" />
+                                <Setter Property="HorizontalContentAlignment"
+                                        Value="Center" />
+                            </Style>
+                        </DataGrid.Resources>
+
+                        <DataGrid.Columns>
+                            <DataGridCheckBoxColumn Binding="{Binding IsSelected}"
+                                                    Header="选择"
+                                                    Width="50" />
+                            <DataGridTextColumn Header="工位类型"
+                                                Binding="{Binding FormulaType}"
+                                                Width="80" />
+                            <DataGridTextColumn Header="关键件条码"
+                                                Binding="{Binding PartNum}"
+                                                Width="120" />
+                            <DataGridTextColumn Header="数量"
+                                                Binding="{Binding PartQty}"
+                                                Width="60">
+                                <DataGridTextColumn.ElementStyle>
+                                    <Style TargetType="TextBlock">
+                                        <Setter Property="HorizontalAlignment"
+                                                Value="Right" />
+                                        <Setter Property="Margin"
+                                                Value="0,0,10,0" />
+                                    </Style>
+                                </DataGridTextColumn.ElementStyle>
+                            </DataGridTextColumn>
+                            <DataGridTextColumn Header="物料代码"
+                                                Binding="{Binding MaterialCode}"
+                                                Width="100" />
+                            <DataGridTextColumn Header="关键件类型"
+                                                Binding="{Binding MaterialType}"
+                                                Width="80" />
+                            <DataGridTextColumn Header="原关键件条码"
+                                                Binding="{Binding OldPartNum}"
+                                                Width="120" />
+                            <DataGridTextColumn Header="位置序号"
+                                                Binding="{Binding PositionNo}"
+                                                Width="80" />
+                            <DataGridTemplateColumn Header="操作"
+                                                    Width="100">
+                                <DataGridTemplateColumn.CellTemplate>
+                                    <DataTemplate>
+                                        <Button Content="删除"
+                                                Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}"
+                                                CommandParameter="{Binding}"
+                                                Background="#F44336"
+                                                Foreground="White"
+                                                Padding="5,2"
+                                                Margin="2,0" />
+                                    </DataTemplate>
+                                </DataGridTemplateColumn.CellTemplate>
+                            </DataGridTemplateColumn>
+                        </DataGrid.Columns>
+                    </DataGrid>
+
+                    <!-- 状态栏 -->
+                    <StatusBar Grid.Row="3"
+                               Background="#F5F5F5">
+                        <StatusBarItem>
+                            <TextBlock>
+                    <Run Text="记录总数:" />
+                    <Run Text="{Binding PartInfos.Count, Mode=OneWay}" />
+                            </TextBlock>
+                        </StatusBarItem>
+                        <StatusBarItem HorizontalAlignment="Right">
+                            <TextBlock Text="{Binding StatusMessage}" />
+                        </StatusBarItem>
+                    </StatusBar>
+                </Grid>
+            </TabItem>
+
             <!-- Tab 4: 绑定记录 -->
             <TabItem Header="绑定记录">
                 <Grid>