taoye 2 lat temu
rodzic
commit
e5a30489a4
38 zmienionych plików z 2755 dodań i 595 usunięć
  1. +110
    -0
      BPASmart.Model/ExpandMethod.cs
  2. +6
    -3
      BPASmart.Model/配方/LocalRecipes.cs
  3. +36
    -0
      BPASmart.Model/配方/Order.cs
  4. +39
    -3
      BPASmart.Model/配方/Recipes.cs
  5. +267
    -1
      BPASmart.RecipeManagement/App.xaml
  6. +28
    -0
      BPASmart.RecipeManagement/BPASmart.RecipeManagement.csproj
  7. +5
    -0
      BPASmart.RecipeManagement/Globle/GlobleData.cs
  8. BIN
     
  9. BIN
     
  10. +9
    -7
      BPASmart.RecipeManagement/MainWindow.xaml
  11. +3
    -6
      BPASmart.RecipeManagement/MainWindow.xaml.cs
  12. +112
    -0
      BPASmart.RecipeManagement/View/CreateOrder.xaml
  13. +37
    -0
      BPASmart.RecipeManagement/View/CreateOrder.xaml.cs
  14. +3
    -156
      BPASmart.RecipeManagement/View/MaterialConfigure.xaml
  15. +1
    -14
      BPASmart.RecipeManagement/View/MaterialManager.xaml
  16. +179
    -0
      BPASmart.RecipeManagement/View/OrderManager.xaml
  17. +30
    -0
      BPASmart.RecipeManagement/View/OrderManager.xaml.cs
  18. +361
    -0
      BPASmart.RecipeManagement/View/PowerManager.xaml
  19. +28
    -0
      BPASmart.RecipeManagement/View/PowerManager.xaml.cs
  20. +158
    -0
      BPASmart.RecipeManagement/View/RecipeManager.xaml
  21. +28
    -0
      BPASmart.RecipeManagement/View/RecipeManager.xaml.cs
  22. +273
    -0
      BPASmart.RecipeManagement/View/RecipesConfigure.xaml
  23. +37
    -0
      BPASmart.RecipeManagement/View/RecipesConfigure.xaml.cs
  24. +12
    -0
      BPASmart.RecipeManagement/View/TechnologySetting.xaml
  25. +28
    -0
      BPASmart.RecipeManagement/View/TechnologySetting.xaml.cs
  26. +62
    -0
      BPASmart.RecipeManagement/ViewModel/CreateOrderViewModel.cs
  27. +1
    -0
      BPASmart.RecipeManagement/ViewModel/MainWindowViewModel.cs
  28. +34
    -0
      BPASmart.RecipeManagement/ViewModel/OrderManagerViewModel.cs
  29. +150
    -0
      BPASmart.RecipeManagement/ViewModel/PowerManagerViewModel.cs
  30. +60
    -0
      BPASmart.RecipeManagement/ViewModel/RecipeManagerViewModel.cs
  31. +115
    -0
      BPASmart.RecipeManagement/ViewModel/RecipesConfigureViewModel.cs
  32. +196
    -196
      BPASmart.Server/CommunicationServer.cs
  33. +169
    -156
      BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs
  34. +3
    -1
      BPASmart.VariableManager/Views/VariableConfig.xaml
  35. +1
    -1
      BPASmartClient.SCADAControl/CustomerControls/TheRadioButton.cs
  36. +93
    -0
      BeDesignerSCADA/Converters/BrowsableAttribute.cs
  37. +58
    -51
      BeDesignerSCADA/ViewModel/MainViewModel.cs
  38. +23
    -0
      SmartClient.sln

+ 110
- 0
BPASmart.Model/ExpandMethod.cs Wyświetl plik

@@ -0,0 +1,110 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmart.Model
{
public static class ExpandMethod
{
/// <summary>
/// 获取数据类型的大小
/// </summary>
/// <param name="eDataType"></param>
/// <returns></returns>
public static ushort GetEDataSize(this EDataType eDataType)
{
switch (eDataType)
{
case EDataType.Bool:
case EDataType.Byte:
case EDataType.Int:
case EDataType.Word:
return 1;
case EDataType.Dint:
case EDataType.Dword:
case EDataType.Float:
return 2;
case EDataType.Double:
break;
case EDataType.String:
break;
default:
break;
}
return 1;
}

/// <summary>
/// 获取Modbus Tcp 连续变量数据的组对象
/// </summary>
/// <param name="variableInfos"></param>
/// <param name="by"></param>
/// <returns></returns>
public static List<ReadDataModel> GetDataGroup(this IGrouping<string, VariableInfo> variableInfos, int by = 1)
{
List<ReadDataModel> ReturnValue = new List<ReadDataModel>();
var res = variableInfos?.OrderBy(p => p.RealAddress).ToList();
List<int> RealAddresss = new List<int>();
variableInfos.ToList()?.ForEach(item => { if (int.TryParse(item.RealAddress, out int add)) RealAddresss.Add(add); });
int count = 0;
if (res != null)
{
int address = RealAddresss.Min();
int startAddress = address;
for (int i = 0; i < res.Count; i++)
{
if (int.TryParse(res.ElementAt(i).RealAddress, out int TempAddress))
{
if (TempAddress == address)
{
count++;
address += by;
}
else
{
ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count });
count = 1;
address = TempAddress + by;
startAddress = TempAddress;
}
}

}
ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count });
}
return ReturnValue;
}

public static Dictionary<EDataType, List<ReadDataModel>> GetReadDataModels(this ObservableCollection<VariableInfo> varialeInfos)
{
Dictionary<EDataType, List<ReadDataModel>> readDataModels = new Dictionary<EDataType, List<ReadDataModel>>();
varialeInfos.GroupBy(p => p.DataType)?.ToList()?.ForEach(tempVar =>
{
if (tempVar.Key != null && tempVar.Key.Length > 0)
{
EDataType dataType = (EDataType)Enum.Parse(typeof(EDataType), tempVar.Key);
switch (dataType)
{
case EDataType.Bool:
case EDataType.Byte:
case EDataType.Int:
case EDataType.Word:
if (!readDataModels.ContainsKey(dataType)) readDataModels.TryAdd(dataType, tempVar.GetDataGroup());
break;
case EDataType.Dint:
case EDataType.Dword:
case EDataType.Float:
if (!readDataModels.ContainsKey(dataType)) readDataModels.TryAdd(dataType, tempVar.GetDataGroup(2));
break;
default:
break;
}
}
});
return readDataModels;
}
}
}

+ 6
- 3
BPASmart.Model/配方/LocalRecipes.cs Wyświetl plik

@@ -1,13 +1,16 @@
using System;

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmart.Model.配方
{
public class LocalRecipes
public class LocalRecipes
{
public ObservableCollection<Recipes> locaRecipes { get; set; } = new ObservableCollection<Recipes>();
}
}

+ 36
- 0
BPASmart.Model/配方/Order.cs Wyświetl plik

@@ -0,0 +1,36 @@
using Microsoft.Toolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmart.Model.配方
{
public class Order:ObservableObject
{
/// <summary>
/// 订单ID
/// </summary>
public string OrderId { get { return _orderId; } set { _orderId = value; OnPropertyChanged(); } }
private string _orderId;

/// <summary>
/// 下单时间
/// </summary>
public string OrderdateTime { get { return _orderDateTime; } set { _orderDateTime = value; OnPropertyChanged(); } }
private string _orderDateTime;

/// <summary>
/// 订单完成时间
/// </summary>
public string OrderCompeleteTime { get { return _orderCompeleteTime; } set { _orderCompeleteTime = value; OnPropertyChanged(); } }
private string _orderCompeleteTime;

/// <summary>
/// 配方集合
/// </summary>
public ObservableCollection<Recipes> Recipes { get; set; } = new ObservableCollection<Recipes>();
}
}

+ 39
- 3
BPASmart.Model/配方/Recipes.cs Wyświetl plik

@@ -1,4 +1,5 @@
using System;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
@@ -7,8 +8,43 @@ using System.Threading.Tasks;

namespace BPASmart.Model.配方
{
public class Recipes
public class Recipes:ObservableObject
{
public ObservableCollection<RecipeMaterials> Materials { get; set; }
/// <summary>
/// 配方ID
/// </summary>
public string ID { get { return _id; } set { _id = value; OnPropertyChanged(); } }
private string _id;

/// <summary>
/// 配方名称
/// </summary>
public string Name { get { return _name; } set { _name = value; OnPropertyChanged(); } }
public string _name;

/// <summary>
/// 配方状态
/// </summary>
public RecipeStates RecipeState { get { return _recipeState; } set { _recipeState = value; OnPropertyChanged(); } }
public RecipeStates _recipeState;

/// <summary>
/// 配方单数
/// </summary>
public int RecipeCount { get { return _recipeCount; } set { _recipeCount = value; OnPropertyChanged(); } }
private int _recipeCount;
/// <summary>
/// 配方原料集合
/// </summary>
public ObservableCollection<RecipeMaterials> recipeMaterials { get; set; }

}

public enum RecipeStates
{
等待制作 = 0,
制作中 = 1,
制作完成 = 2
}
}


+ 267
- 1
BPASmart.RecipeManagement/App.xaml Wyświetl plik

@@ -4,6 +4,272 @@
xmlns:local="clr-namespace:BPASmart.RecipeManagement"
StartupUri="MainWindow.xaml">
<Application.Resources>
<Style TargetType="{x:Type ContextMenu}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContextMenu}">
<Border x:Name="Border" CornerRadius="4" Background="#009ACD" BorderThickness="1" Margin="0">
<Border.BorderBrush>
<SolidColorBrush Color="#104E8B" />
</Border.BorderBrush>
<ItemsPresenter/>
</Border>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True"/>
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(FrameworkElement.Width)">
<SplineDoubleKeyFrame KeyTime="00:00:00.0020000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.20000" Value="110"/>
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(FrameworkElement.Height)">
<SplineDoubleKeyFrame KeyTime="00:00:00.0020000" Value="0"/>
<SplineDoubleKeyFrame KeyTime="00:00:00.20000" Value="100"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</MultiTrigger.EnterActions>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type MenuItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuItem}">
<Border Margin="0,5" MinWidth="80" CornerRadius="5">
<Border.Background>
<SolidColorBrush x:Name="MyAnimatedBrushBackground" Color="Transparent" />
</Border.Background>
<StackPanel Orientation="Horizontal">
<TextBlock Text=" "/>
<ContentPresenter ContentSource="Icon" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBlock Text=" "/>
<ContentPresenter ContentSource="Header" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
</Border>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True"/>
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="MyAnimatedBrushBackground" Storyboard.TargetProperty="Color">
<LinearColorKeyFrame Value="Transparent" KeyTime="00:00:00.0020000" />
<LinearColorKeyFrame Value="#B0E2FF" KeyTime="00:00:00.0320000" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="MyAnimatedBrushBackground" Storyboard.TargetProperty="Color">
<LinearColorKeyFrame Value="#7E9C9C9C" KeyTime="00:00:00.0020000" />
<LinearColorKeyFrame Value="Transparent" KeyTime="00:00:00.0320000" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</MultiTrigger.ExitActions>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<ControlTemplate x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
<Grid Height="25" HorizontalAlignment="Stretch" Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="30" />
</Grid.ColumnDefinitions>
<Border
Grid.ColumnSpan="2"
Background="White"
Opacity="0" />

<Path
x:Name="Arrow"
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="M 0 0 6 6 12 0 Z"
Fill="Black"
Stretch="None">
<Path.Effect>
<DropShadowEffect
BlurRadius="10"
Direction="90"
Opacity="1"
RenderingBias="Quality"
ShadowDepth="0"
Color="Transparent" />
</Path.Effect>
</Path>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="true">
<Setter TargetName="Arrow" Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="180" CenterX="6" CenterY="3" />
</Setter.Value>
</Setter>
<Setter TargetName="Arrow" Property="Margin" Value="0,0,0,2" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>

<Style TargetType="{x:Type ComboBox}">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Background" Value="White"/>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="ComboBoxItem">
<Setter Property="Height" Value="25" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
<Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
<Border x:Name="_borderbg" Background="White" />

<TextBlock
x:Name="_txt"
Margin="5,0,3,0"
FontWeight="Black"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Foreground="Black"
Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" />

<Border
x:Name="_border"
Background="White"
Opacity="0" />
</Grid>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="false" />
<Condition Property="IsMouseOver" Value="true" />
</MultiTrigger.Conditions>
<Setter TargetName="_borderbg" Property="Background" Value="#AFEEEE" />
<Setter TargetName="_txt" Property="Foreground" Value="black" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>


<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<Grid>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.7*" />
<ColumnDefinition Width="0.3*" MaxWidth="30" />
</Grid.ColumnDefinitions>
<Border
x:Name="_prybr"
Grid.Column="0"
Grid.ColumnSpan="2"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="0" />
<ContentPresenter
x:Name="ContentSite"
Margin="3,3,0,3"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
IsHitTestVisible="False" />

<!-- ToggleButton 已数据绑定到 ComboBox 本身以切换 IsDropDownOpen -->
<ToggleButton
x:Name="ToggleButton"
Grid.Column="0"
Grid.ColumnSpan="2"
ClickMode="Press"
Focusable="false"
IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Template="{StaticResource ComboBoxToggleButton}" />
<!-- 必须将 TextBox 命名为 PART_EditableTextBox,否则 ComboBox 将无法识别它 -->
<TextBox
x:Name="PART_EditableTextBox"
Margin="2,0,0,0"
VerticalAlignment="Center"
Background="White"
BorderThickness="0"
CaretBrush="{TemplateBinding Foreground}"
Focusable="True"
Foreground="{TemplateBinding Foreground}"
IsReadOnly="{TemplateBinding IsReadOnly}"
Visibility="Hidden" />

<!-- Popup 可显示 ComboBox 中的项列表。IsOpen 已数据绑定到通过 ComboBoxToggleButton 来切换的 IsDropDownOpen -->
<Popup
x:Name="Popup"
AllowsTransparency="True"
Focusable="False"
IsOpen="{TemplateBinding IsDropDownOpen}"
Placement="Bottom"
PopupAnimation="Slide">
<Grid
x:Name="DropDown"
MinWidth="{TemplateBinding ActualWidth}"
MaxHeight="150"
SnapsToDevicePixels="True">
<Border
x:Name="DropDownBorder"
BorderBrush="Black"
BorderThickness="0" />
<ScrollViewer
Margin="1"
CanContentScroll="True"
HorizontalScrollBarVisibility="Auto"
SnapsToDevicePixels="True"
VerticalScrollBarVisibility="Auto">
<!-- StackPanel 用于显示子级,方法是将 IsItemsHost 设置为 True -->
<!-- 一下可以设置列表背景色 -->
<StackPanel
Background="White"
IsItemsHost="True"
KeyboardNavigation.DirectionalNavigation="Contained" />
</ScrollViewer>
</Grid>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEditable" Value="true">
<Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="_prybr" Property="BorderBrush" Value="#aa3ba7f2" />

</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="ContentSite" Property="Opacity" Value="0.6" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
</Application>

+ 28
- 0
BPASmart.RecipeManagement/BPASmart.RecipeManagement.csproj Wyświetl plik

@@ -15,9 +15,37 @@
<Page Remove="新文件夹1\**" />
</ItemGroup>

<ItemGroup>
<None Remove="Image\AddGreen.png" />
<None Remove="Image\Delete.png" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BPASmart.Model\BPASmart.Model.csproj" />
<ProjectReference Include="..\BPASmartClient.Model\BPASmartClient.Model.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="View\RecipesConfigure.xaml.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>

<ItemGroup>
<Page Update="View\RecipesConfigure.xaml">
<XamlRuntime>$(DefaultXamlRuntime)</XamlRuntime>
<SubType>Designer</SubType>
</Page>
</ItemGroup>

<ItemGroup>
<Resource Include="Image\Delete.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
</ItemGroup>

<ItemGroup>
<Resource Include="Image\AddGreen.png" />
</ItemGroup>

</Project>

+ 5
- 0
BPASmart.RecipeManagement/Globle/GlobleData.cs Wyświetl plik

@@ -1,6 +1,7 @@
using BPASmart.Model.配方;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -10,5 +11,9 @@ namespace BPASmart.RecipeManagement.Globle
public class GlobleData
{
public static RecipeMaterials ChangeMaterail;

public static Recipes ChangeRecipes;

public static ObservableCollection<Order> orders { get; set; } = new ObservableCollection<Order>();
}
}



+ 9
- 7
BPASmart.RecipeManagement/MainWindow.xaml Wyświetl plik

@@ -7,7 +7,7 @@
xmlns:view="clr-namespace:BPASmart.RecipeManagement.View"
xmlns:vm="clr-namespace:BPASmart.RecipeManagement.ViewModel"
mc:Ignorable="d"
Title="MainWindow" Height="900" Width="1600" WindowStyle="None" WindowStartupLocation="CenterScreen">
Title="MainWindow" Height="900" Width="1400" WindowStyle="None" WindowStartupLocation="CenterScreen">
<Window.DataContext>
<vm:MainWindowViewModel/>
</Window.DataContext>
@@ -81,14 +81,16 @@
<StackPanel x:Name="mylistview" Background="#2196F3" Grid.RowSpan="2"
ScrollViewer.VerticalScrollBarVisibility="Hidden" ScrollViewer.HorizontalScrollBarVisibility="Hidden"
MouseDown="mylistview_MouseDown" >
<RadioButton Content="配方管理" Style="{DynamicResource RadioNavigation}" IsChecked="True"
Click="NavButton_Click" Tag=""/>
<RadioButton Content="订单管理" Style="{DynamicResource RadioNavigation}" IsChecked="True"
Click="NavButton_Click" Tag="OrderManager"/>
<RadioButton Content="配方管理" Style="{DynamicResource RadioNavigation}"
Click="NavButton_Click" Tag="RecipeManager"/>
<RadioButton Content="原料管理" Style="{DynamicResource RadioNavigation}"
Click="NavButton_Click" Tag=""/>
Click="NavButton_Click" Tag="MaterialManager"/>
<RadioButton Content="工艺参数" Style="{DynamicResource RadioNavigation}"
Click="NavButton_Click" Tag=""/>
Click="NavButton_Click" Tag="TechnologySetting"/>
<RadioButton Content="权限分配" Style="{DynamicResource RadioNavigation}"
Click="NavButton_Click" Tag=""/>
Click="NavButton_Click" Tag="PowerManager"/>
</StackPanel>
<Border Background="#2196F3" Grid.Row="2">
<Button Content="退出"
@@ -98,7 +100,7 @@
</Button>
</Border>
<ContentControl x:Name="contentRegion" Grid.Column="1" Grid.Row="1" >
<view:MaterialManager/>
<view:PowerManager/>
</ContentControl>
</Grid>
</Border>


+ 3
- 6
BPASmart.RecipeManagement/MainWindow.xaml.cs Wyświetl plik

@@ -40,16 +40,13 @@ namespace BPASmart.RecipeManagement

private void NavButton_Click(object sender, RoutedEventArgs e)
{

try
{
if (sender is Button bt)
if (sender is RadioButton bt)
{
Type type = Type.GetType($"BPASmartClient.MilkWithTea.View.{bt.Tag?.ToString()}");
Type type = Type.GetType($"BPASmart.RecipeManagement.View.{bt.Tag?.ToString()}");
ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes);
contentRegion.Content = (FrameworkElement)cti.Invoke(null);
contentRegion.Content = (FrameworkElement)cti.Invoke(null);
}
}
catch (Exception ex)


+ 112
- 0
BPASmart.RecipeManagement/View/CreateOrder.xaml Wyświetl plik

@@ -0,0 +1,112 @@
<Window x:Class="BPASmart.RecipeManagement.View.CreateOrder"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BPASmart.RecipeManagement.View"
xmlns:vm="clr-namespace:BPASmart.RecipeManagement.ViewModel"
mc:Ignorable="d"
Title="CreateOrder" Height="250" Width="400" WindowStartupLocation="CenterScreen" WindowStyle="None" Background="White" MouseLeftButtonDown="Window_MouseLeftButtonDown">
<Window.DataContext>
<vm:CreateOrderViewModel/>
</Window.DataContext>
<Window.Resources>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="*"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Button Content="增加配方" Width="100" Height="30" HorizontalAlignment="Right" Margin="10,0"
Background="#58B0ED" Foreground="White" Command="{Binding AddRecipeCommand}"/>

<Border Grid.Row="1" BorderBrush="#B0E2FF" BorderThickness="0,1">
<ItemsControl ItemsSource="{Binding recipes}" Grid.Row="1" HorizontalAlignment="Center">
<ItemsControl.ItemTemplate>
<DataTemplate>
<RadioButton GroupName="all">
<RadioButton.Template>
<ControlTemplate TargetType="RadioButton">
<Grid Name="gr" Height="40">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="60" />
</Grid.ColumnDefinitions>

<ComboBox
Name="cb"
Grid.Column="0"
Margin="3,1"
VerticalAlignment="Center"
BorderBrush="Black"
BorderThickness="1"
FontFamily="楷体"
FontSize="20"
Foreground="Black"
IsEditable="False"
ItemsSource="{Binding DataContext.recipesName, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}"
SelectedItem="{Binding Name}"
/>


<StackPanel
Grid.Column="1"
VerticalAlignment="Center"
Orientation="Horizontal">
<TextBox
Name="tb"
Grid.Column="1"
Width="60"
Height="29"
Margin="3,1"
VerticalAlignment="Center"
FontSize="20"
Text="{Binding RecipeCount}" />

<TextBlock
Grid.Column="1"
Margin="0,0,8,4"
HorizontalAlignment="Right"
VerticalAlignment="Center"
FontSize="20"
Text="单" />

</StackPanel>

<Button
Grid.Column="2"
Width="50"
Height="24"
Foreground="White"
FontSize="14"
Background="#58B0ED"
Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}"
CommandParameter="{Binding ID}"
Content="删 除" />

</Grid>


</ControlTemplate>
</RadioButton.Template>
</RadioButton>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Border>

<StackPanel Grid.Row="4" Grid.ColumnSpan="3" Orientation="Horizontal"
HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Content="保存" Foreground="White" FontSize="22" Width="120" Height="30" Margin="10,2" Background="#58B0ED"
Command="{Binding SaveCommand}"/>
<Button Content="取消" Foreground="White" FontSize="22" Width="120" Height="30" Margin="10,2" Background="#58B0ED"
Click="Button_Click"/>


</StackPanel>
</Grid>
</Window>

+ 37
- 0
BPASmart.RecipeManagement/View/CreateOrder.xaml.cs Wyświetl plik

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace BPASmart.RecipeManagement.View
{
/// <summary>
/// CreateOrder.xaml 的交互逻辑
/// </summary>
public partial class CreateOrder : Window
{
public CreateOrder()
{
InitializeComponent();
}

private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}

+ 3
- 156
BPASmart.RecipeManagement/View/MaterialConfigure.xaml Wyświetl plik

@@ -11,162 +11,9 @@
<vm:MaterialConfigureViewModel/>
</Window.DataContext>
<Window.Resources>
<Style TargetType="{x:Type ComboBox}">
<Setter Property="Background" Value="White"/>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<!--ComBoxItem-->
<Style TargetType="ComboBoxItem">
<Setter Property="MinHeight" Value="22"></Setter>
<Setter Property="MinWidth" Value="60"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBoxItem">
<Border Name="Back" Background="Transparent" BorderThickness="0,0,0,0" BorderBrush="#81D779" >
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5,0,0,0"></ContentPresenter>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Back" Property="Background" Value="LightGray"></Setter>
</Trigger>
<Trigger Property="IsHighlighted" Value="True">
<Setter TargetName="Back" Property="Background" Value="LightGray"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<Border BorderThickness="1" BorderBrush="#CDC9C9 " CornerRadius="3" Width="{TemplateBinding Width}" Height="40" Background="{TemplateBinding Background}" >
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0" x:Name="grid">
<ToggleButton
Width="{Binding ElementName=grid,Path=ActualWidth}"
Height="{Binding ElementName=grid, Path=ActualHeight}"
Content="{TemplateBinding Text}" VerticalAlignment="Center"
HorizontalAlignment="Left" Margin="5,0,0,0"
BorderThickness="0"
Foreground="{TemplateBinding Foreground}"
Background="{TemplateBinding Background}"
IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"
>
<ToggleButton.Style >
<Style TargetType="ToggleButton">
<Setter Property="Background" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Border Background="{TemplateBinding Background}" BorderThickness="0" >
<TextBlock Foreground="{TemplateBinding Foreground}" Text="{TemplateBinding Content}" Margin="4 0 0 0" HorizontalAlignment="Left" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="White"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="Background" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
</ToggleButton.Style>
</ToggleButton>
</Grid>

<Grid Grid.Column="1" >
<ToggleButton IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Foreground="{TemplateBinding Foreground}"
ClickMode="Press">
<ToggleButton.Style>
<Style TargetType="ToggleButton">
<Setter Property="Background" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Border Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}">
<Grid>
<Image Source="pack://application:,,,/image/down,png" Stretch="Fill" HorizontalAlignment="Center" VerticalAlignment="Center">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Image.RenderTransform>
</Image>
</Grid>
</Border>
<!--<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">

</Trigger>
<EventTrigger RoutedEvent="Checked">
<BeginStoryboard>
<Storyboard >
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="arrow_tb" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
<EasingDoubleKeyFrame KeyTime="00:00:00.2000000" Value="180"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>

<EventTrigger RoutedEvent="Unchecked">
<BeginStoryboard>
<Storyboard >
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="arrow_tb" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">
<EasingDoubleKeyFrame KeyTime="00:00:00" Value="180"/>
<EasingDoubleKeyFrame KeyTime="00:00:00.2000000" Value="0"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers>-->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ToggleButton.Style>
</ToggleButton>
</Grid>
<Popup IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" x:Name="Popup" Focusable="False" AllowsTransparency="True" PopupAnimation="Slide">
<Border CornerRadius="1" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}" x:Name="DropDown" SnapsToDevicePixels="True">
<Border.Effect>
<DropShadowEffect Color="Black" BlurRadius="2" ShadowDepth="0" Opacity="0.5"/>
</Border.Effect>
<ScrollViewer Margin="4,6,4,6" MaxHeight="{TemplateBinding MaxDropDownHeight}" SnapsToDevicePixels="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" CanContentScroll="True">
<!-- StackPanel 用于显示子级,方法是将 IsItemsHost 设置为 True -->
<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" Background="White"/>
</ScrollViewer>
</Border>
</Popup>
</Grid>


<Border.Effect>
<DropShadowEffect ShadowDepth="-1" Opacity="0.3" Color="#FF969696" BlurRadius="5"/>
</Border.Effect>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>


</Style>
</Window.Resources>
<Border CornerRadius="20" Background="#FFFAFA">
<Border CornerRadius="20" Background="White">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="17*"/>
@@ -188,7 +35,7 @@
<TextBox Text="{Binding MaterialName}" FontSize="22" Grid.Column="1" Width="200" Height="40"
VerticalAlignment="Center" HorizontalAlignment="Center"
VerticalContentAlignment="Center"/>
<ComboBox ItemsSource="{Binding MaterialTypes}"
<ComboBox ItemsSource="{Binding MaterialTypes}"
FontSize="18"
Grid.Column="1" Grid.Row="1" Width="200" Height="40"
SelectedItem="{Binding MaterialType}"/>


+ 1
- 14
BPASmart.RecipeManagement/View/MaterialManager.xaml Wyświetl plik

@@ -14,9 +14,7 @@
<Style TargetType="ListViewItem" >
<Setter Property="Margin" Value="60,20"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border x:Name="mborder" BorderBrush="#009AC0" BorderThickness="1,5" CornerRadius="10">
@@ -179,18 +177,7 @@
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<!--<ContextMenu>
<ContextMenu FontSize="16" Foreground="White">
<MenuItem Header="新建原料" Name="MenuCreate"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.CreateMaterailCommand}"></MenuItem>
<MenuItem Header="编辑原料" Name="MenuEdit"
Command="{Binding RelativeSource={RelativeSource Mode= FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.EditMaterailCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListView}},Path=SelectedItem}"></MenuItem>
<MenuItem Header="删除原料" Name="MenuDelete"
Command="{Binding RelativeSource={RelativeSource Mode= FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.DeleteMaterailCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListView}},Path=SelectedItem}"></MenuItem>
</ContextMenu>
</ContextMenu>-->
</ListView>
</Grid>


+ 179
- 0
BPASmart.RecipeManagement/View/OrderManager.xaml Wyświetl plik

@@ -0,0 +1,179 @@
<UserControl x:Class="BPASmart.RecipeManagement.View.OrderManager"
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:BPASmart.RecipeManagement.View"
xmlns:vm ="clr-namespace:BPASmart.RecipeManagement.ViewModel"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.DataContext>
<vm:OrderManagerViewModel/>
</UserControl.DataContext>
<UserControl.Resources>
<Style TargetType="ListBoxItem">
<Setter Property="Margin" Value="2"/>
<Setter Property="FontSize" Value="22"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border BorderBrush="Black" BorderThickness="1">
<Grid HorizontalAlignment="Center" Margin="10 ">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0"
Margin="5,0,0,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Foreground="Black"
Text="配方:" />
<TextBlock
Grid.Row="1"
Margin="5,0,0,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Foreground="Black"
Text="数量:" />
<TextBlock
Grid.Row="2"
Margin="5,0,0,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Foreground="Black"
Text="已完成:" />
<TextBlock
Grid.Row="0"
Grid.Column="1"
Margin="5,0,0,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Foreground="Black"
Text="{Binding Name}" />
<TextBlock
Grid.Row="1"
Grid.Column="1"
Margin="5,0,0,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Foreground="Black"
Text="{Binding RecipeCount}" />
<TextBlock
Grid.Row="2"
Grid.Column="1"
Margin="5,0,0,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Foreground="Black"
Text="" />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="ListViewItem" >
<Setter Property="Margin" Value="10"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border x:Name="mborder" BorderBrush="#009AC0" BorderThickness="3,3,3,10" CornerRadius="10" Margin="10"
Background="White">
<Border.Effect>
<DropShadowEffect Color="#696969" Direction="215" ShadowDepth="10" Opacity="0.8"/>
</Border.Effect>
<Grid
Name="tt"
Height="250"
Width="300"
Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
<RowDefinition Height="2" />
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock
Grid.Row="0"
Margin="2,5,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Top"
FontSize="18"
Foreground="Black"
Text="下单时间: " />
<TextBlock
Grid.Row="0"
Margin="2,5,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Top"
FontSize="18"
Foreground="Black"
Text="{Binding OrderdateTime}" />
</StackPanel>
<ScrollViewer
Grid.Row="1"
Margin="20,10"
VerticalAlignment="Top"
Background="Transparent"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Auto">
<ListBox ItemsSource="{Binding Recipes}" FontFamily="楷体">
</ListBox>

</ScrollViewer>
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Content="执行订单" Width="100" Height="24" HorizontalAlignment="Right" Margin="10,0"
Background="#58B0ED" Foreground="White"
Command="{Binding }"
/>
<Button Content="删除订单" Width="100" Height="24" HorizontalAlignment="Right" Margin="10,0"
Background="#58B0ED" Foreground="White"
Command="{Binding }"
CommandParameter="{Binding}"/>
</StackPanel>
</Grid>

</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="#D2B48C" TargetName="mborder"/>
</Trigger>
<Trigger Property="IsFocused" Value="True">

</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition />
</Grid.RowDefinitions>
<Button Content="创建订单" Width="100" Height="30" HorizontalAlignment="Right" Margin="10,0"
Background="#58B0ED" Foreground="White" Command="{Binding CreateOrderCommand}"/>
<ListView Grid.Row="1"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding orders}" Background="#FFFAFA" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Margin="10"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListView>
</Grid>
</UserControl>

+ 30
- 0
BPASmart.RecipeManagement/View/OrderManager.xaml.cs Wyświetl plik

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BPASmart.RecipeManagement.View
{
/// <summary>
/// OrderManager.xaml 的交互逻辑
/// </summary>
public partial class OrderManager : UserControl
{
public OrderManager()
{
InitializeComponent();
}

}
}

+ 361
- 0
BPASmart.RecipeManagement/View/PowerManager.xaml Wyświetl plik

@@ -0,0 +1,361 @@
<UserControl x:Class="BPASmart.RecipeManagement.View.PowerManager"
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:BPASmart.RecipeManagement.View"
xmlns:vm="clr-namespace:BPASmart.RecipeManagement.ViewModel"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.DataContext>
<vm:PowerManagerViewModel/>
</UserControl.DataContext>
<UserControl.Resources>
<ImageBrush x:Key="ImageBrushAddBlue" ImageSource="../Image/AddGreen.png"></ImageBrush>
<ImageBrush x:Key="ImageBrushAddGray" ImageSource="../Image/Delete.png"></ImageBrush>

<Style x:Key="ScrollBarPageButton" TargetType="{x:Type RepeatButton}">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="IsTabStop" Value="false" />
<Setter Property="Focusable" Value="false" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type RepeatButton}">
<Border Background="Transparent" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style x:Key="ItemContainer" TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="IconBorder" Background="Transparent" CornerRadius="4" BorderThickness="0">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="IconBorder" Property="BitmapEffect">
<Setter.Value>
<OuterGlowBitmapEffect GlowColor="Transparent" GlowSize="5" />
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="IsTabStop" Value="false" />
<Setter Property="Focusable" Value="false" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border CornerRadius="2" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

<ControlTemplate x:Key="VerticalScrollBar" TargetType="{x:Type ScrollBar}">
<Grid>
<Border CornerRadius="2" Width="0.5" Background="#FF046BFF" />
<Track x:Name="PART_Track" IsDirectionReversed="true">
<Track.DecreaseRepeatButton>
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageUpCommand" />
</Track.DecreaseRepeatButton>
<Track.Thumb>
<Thumb Style="{StaticResource ScrollBarThumb}" Margin="4,0,4,0" Background="DodgerBlue"></Thumb>
</Track.Thumb>
<Track.IncreaseRepeatButton>
<RepeatButton Style="{StaticResource ScrollBarPageButton}" Command="ScrollBar.PageDownCommand" />
</Track.IncreaseRepeatButton>
</Track>
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="ScrollViewerControlTemplate1" TargetType="{x:Type ScrollViewer}">
<Grid x:Name="Grid" Background="{TemplateBinding Background}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Rectangle x:Name="Corner" Grid.Column="1" Fill="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Grid.Row="1"/>
<ScrollContentPresenter x:Name="PART_ScrollContentPresenter" CanContentScroll="{TemplateBinding CanContentScroll}" CanHorizontallyScroll="False" CanVerticallyScroll="False" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Grid.Column="0" Margin="{TemplateBinding Padding}" Grid.Row="0"/>
<ScrollBar x:Name="PART_VerticalScrollBar" AutomationProperties.AutomationId="VerticalScrollBar" Cursor="Arrow" Grid.Column="1"
Maximum="{TemplateBinding ScrollableHeight}" Minimum="0" Grid.Row="0" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportHeight}"
Template="{StaticResource VerticalScrollBar}"/>
<ScrollBar x:Name="PART_HorizontalScrollBar" AutomationProperties.AutomationId="HorizontalScrollBar" Cursor="Arrow" Grid.Column="0" Maximum="{TemplateBinding ScrollableWidth}" Minimum="0" Orientation="Horizontal" Grid.Row="1" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" ViewportSize="{TemplateBinding ViewportWidth}"/>
</Grid>
</ControlTemplate>
</UserControl.Resources>
<Grid Margin="0,10">
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="20"/>
<RowDefinition Height="40"/>
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="选择用户" FontSize="22" Foreground="DarkSlateGray" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="20,0"/>
<ComboBox Width="120" Margin="20,0" ItemsSource="{Binding UserName }" FontSize="16"/>
<Button Foreground="White" Background="#009DFF" Margin="20,0"
FontSize="18" Height="30" Width="120"
Command="{Binding SaveCommand}" CommandParameter="Materials">
<TextBlock Text="保存" TextWrapping="Wrap"/>
</Button>

</StackPanel>

<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Text="原料权限" FontSize="22" Foreground="DarkSlateGray" VerticalAlignment="Bottom" HorizontalAlignment="Center" />
<TextBlock Grid.Column="1" Text="配方权限" FontSize="22" Foreground="DarkSlateGray" VerticalAlignment="Bottom" HorizontalAlignment="Center" />
</Grid>
<Grid Grid.Row="3" Margin="5,10,5,50">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="70"/>
<ColumnDefinition/>
<ColumnDefinition Width="20"/>
<ColumnDefinition/>
<ColumnDefinition Width="70"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<!--#region原料权限-->
<Border Grid.Column="0" BorderBrush="#1874CD" BorderThickness="1" />
<Border Grid.Column="2" BorderBrush="#1874CD" BorderThickness="1" />
<ScrollViewer Margin="5" Template="{StaticResource ScrollViewerControlTemplate1}" CanContentScroll="True"
Width="auto">
<ListBox Background="Transparent" ItemContainerStyle="{StaticResource ItemContainer}" FocusVisualStyle="{x:Null}"
ItemsSource="{Binding AllMaterials}" >
<ListBox.Template>
<ControlTemplate>
<StackPanel Background="Transparent" IsItemsHost="True"></StackPanel>
</ControlTemplate>
</ListBox.Template>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="28" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="60"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock x:Name="tb_Name" Text="{Binding Name}" Foreground="Black" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Left" />
<Button x:Name="BtnDelete" Grid.Column="1" Background="Transparent" ToolTip="移除" VerticalAlignment="Center" HorizontalAlignment="Left"
Command="{Binding DataContext.AddMaterialCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"
CommandParameter="{Binding Path=Text,ElementName=tb_Name}">
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid>
<Rectangle x:Name="BtnRetangle" Height="21" Width="21" Stroke="Transparent" StrokeThickness="1" VerticalAlignment="Center" HorizontalAlignment="Left">
<Rectangle.Fill>
<ImageBrush ImageSource="../Image/AddGreen.png"></ImageBrush>
</Rectangle.Fill>
</Rectangle>
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" Content="{TemplateBinding Content}"></ContentPresenter>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="BtnRetangle" Property="Height" Value="24"></Setter>
<Setter TargetName="BtnRetangle" Property="Width" Value="24"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>

<StackPanel Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Foreground="White" Background="#009DFF"
FontSize="18" Height="60" Width="60" Margin="0,20"
Command="{Binding AddAllCommand}" CommandParameter="Materials">
<TextBlock Text="全部
添加" TextWrapping="Wrap"/>
</Button>
<Button Foreground="White" Background="#009DFF"
FontSize="18" Height="60" Width="60" Margin="0,20"
Command="{Binding DeleteAllCommand}" CommandParameter="Materials">
<TextBlock Text="全部
移除" TextWrapping="Wrap"/>
</Button>
</StackPanel>

<ScrollViewer Grid.Column="2" Margin="5" Template="{StaticResource ScrollViewerControlTemplate1}" CanContentScroll="True">
<ListBox Background="Transparent" ItemContainerStyle="{StaticResource ItemContainer}" FocusVisualStyle="{x:Null}" Width="auto"
ItemsSource="{Binding UserMaterials}" >
<ListBox.Template>
<ControlTemplate>
<StackPanel Background="Transparent" IsItemsHost="True"></StackPanel>
</ControlTemplate>
</ListBox.Template>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="28" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="60"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock x:Name="tb_Name" Text="{Binding Name}" Foreground="Black" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Left" />
<Button x:Name="BtnDelete" Grid.Column="1" Background="Transparent" ToolTip="移除" VerticalAlignment="Center" HorizontalAlignment="Left"
Command="{Binding DataContext.DeleteMaterialCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"
CommandParameter="{Binding Path=Text,ElementName=tb_Name}">
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid>
<Rectangle x:Name="BtnRetangle" Height="21" Width="21" Stroke="Transparent" StrokeThickness="1" VerticalAlignment="Center" HorizontalAlignment="Left">
<Rectangle.Fill>
<ImageBrush ImageSource="../Image/Delete.png"></ImageBrush>
</Rectangle.Fill>
</Rectangle>
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" Content="{TemplateBinding Content}"></ContentPresenter>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="BtnRetangle" Property="Height" Value="24"></Setter>
<Setter TargetName="BtnRetangle" Property="Width" Value="24"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
<!--#endregion-->
<!--#region 配方权限-->
<Border Grid.Column="4" BorderBrush="#1874CD" BorderThickness="1" />
<Border Grid.Column="6" BorderBrush="#1874CD" BorderThickness="1" />
<ScrollViewer Grid.Column="4" Width="auto" Margin="5,5,5,5" Template="{StaticResource ScrollViewerControlTemplate1}" CanContentScroll="True" >
<ListBox Background="Transparent" ItemContainerStyle="{StaticResource ItemContainer}" FocusVisualStyle="{x:Null}"
ItemsSource="{Binding AllRecipes}" >
<ListBox.Template>
<ControlTemplate>
<StackPanel Background="Transparent" IsItemsHost="True"></StackPanel>
</ControlTemplate>
</ListBox.Template>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="28" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="60"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock x:Name="tb_Name" Text="{Binding Name}" Foreground="Black" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Left" />
<Button x:Name="BtnDelete" Grid.Column="1" Background="Transparent" ToolTip="移除" VerticalAlignment="Center" HorizontalAlignment="Left"
Command="{Binding DataContext.AddRecipeCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"
CommandParameter="{Binding Path=Text,ElementName=tb_Name}">
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid>
<Rectangle x:Name="BtnRetangle" Height="21" Width="21" Stroke="Transparent" StrokeThickness="1" VerticalAlignment="Center" HorizontalAlignment="Left">
<Rectangle.Fill>
<ImageBrush ImageSource="../Image/AddGreen.png"></ImageBrush>
</Rectangle.Fill>
</Rectangle>
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" Content="{TemplateBinding Content}"></ContentPresenter>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="BtnRetangle" Property="Height" Value="24"></Setter>
<Setter TargetName="BtnRetangle" Property="Width" Value="24"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>

<StackPanel Grid.Column="5" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Foreground="White" Background="#009DFF"
FontSize="18" Height="60" Width="60" Margin="0,20"
Command="{Binding AddAllCommand}" CommandParameter="Recipes">
<TextBlock Text="全部
添加" TextWrapping="Wrap"/>
</Button>
<Button Foreground="White" Background="#009DFF"
FontSize="18" Height="60" Width="60" Margin="0,20"
Command="{Binding DeleteAllCommand}" CommandParameter="Recipes">
<TextBlock Text="全部
移除" TextWrapping="Wrap"/>
</Button>
</StackPanel>


<ScrollViewer Grid.Column="6" Margin="5" Template="{StaticResource ScrollViewerControlTemplate1}" CanContentScroll="True">
<ListBox Background="Transparent" ItemContainerStyle="{StaticResource ItemContainer}" FocusVisualStyle="{x:Null}"
Width="auto"
ItemsSource="{Binding UserRecipes}" >
<ListBox.Template>
<ControlTemplate>
<StackPanel Background="Transparent" IsItemsHost="True"></StackPanel>
</ControlTemplate>
</ListBox.Template>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Height="28" Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="60"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock x:Name="tb_Name" Text="{Binding Name}" Foreground="Black" FontSize="18" VerticalAlignment="Center" HorizontalAlignment="Left" />
<Button x:Name="BtnDelete" Grid.Column="1" Background="Transparent" ToolTip="移除" VerticalAlignment="Center" HorizontalAlignment="Left"
Command="{Binding DataContext.DeleteRecipeCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"
CommandParameter="{Binding Path=Text,ElementName=tb_Name}">
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid>
<Rectangle x:Name="BtnRetangle" Height="21" Width="21" Stroke="Transparent" StrokeThickness="1" VerticalAlignment="Center" HorizontalAlignment="Left">
<Rectangle.Fill>
<ImageBrush ImageSource="../Image/Delete.png"></ImageBrush>
</Rectangle.Fill>
</Rectangle>
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" Content="{TemplateBinding Content}"></ContentPresenter>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="BtnRetangle" Property="Height" Value="24"></Setter>
<Setter TargetName="BtnRetangle" Property="Width" Value="24"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>


<!--#endregion-->


</Grid>
</Grid>
</UserControl>

+ 28
- 0
BPASmart.RecipeManagement/View/PowerManager.xaml.cs Wyświetl plik

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BPASmart.RecipeManagement.View
{
/// <summary>
/// PowerManager.xaml 的交互逻辑
/// </summary>
public partial class PowerManager : UserControl
{
public PowerManager()
{
InitializeComponent();
}
}
}

+ 158
- 0
BPASmart.RecipeManagement/View/RecipeManager.xaml Wyświetl plik

@@ -0,0 +1,158 @@
<UserControl x:Class="BPASmart.RecipeManagement.View.RecipeManager"
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:BPASmart.RecipeManagement.View"
xmlns:vm="clr-namespace:BPASmart.RecipeManagement.ViewModel"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl.DataContext>
<vm:RecipeManagerViewModel/>
</UserControl.DataContext>
<UserControl.Resources>
<Style TargetType="ListViewItem" >
<Setter Property="Margin" Value="10"/>

<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<Border x:Name="mborder" BorderBrush="#009AC0" BorderThickness="1,5" CornerRadius="10" Margin="10"
Background="Transparent">
<Grid
Name="tt"
Height="200"
Width="150"
Margin="5">
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="20" />
<RowDefinition Height="128" />
<RowDefinition Height="2" />
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Margin="2,5,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Top"
FontSize="18"
Foreground="Black"
Text="{Binding Name}" />

<TextBlock
Grid.Row="1"
Margin="5,0,0,0"
VerticalAlignment="Top"
Foreground="Black"
Text="配方信息:" />

<ScrollViewer
Grid.Row="2"
VerticalAlignment="Top"
Background="Transparent"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Hidden">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>

<ItemsControl ItemsSource="{Binding recipeMaterials}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock
Grid.Row="1"
Margin="5,0,0,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Foreground="#FF2AB2E7"
Text="{Binding Name}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

<ItemsControl Grid.Column="1"
VerticalAlignment="Center"
VerticalContentAlignment="Center" ItemsSource="{Binding recipeMaterials}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">

<TextBlock
Margin="5,0,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="#FF2AB2E7"
Text=":" />

<TextBlock
Margin="5,0,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="#FF2AB2E7"
Text="{Binding MaterialWeight}" />

<TextBlock
Margin="5,0,0,0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="#FF2AB2E7"
Text="g" />

</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

</Grid>

</ScrollViewer>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="#D2B48C" TargetName="mborder"/>

</Trigger>
<Trigger Property="IsFocused" Value="True">

</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

</UserControl.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="配方清单" FontSize="28" Foreground="DarkSlateGray" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<ListView Grid.Row="1"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" ItemsSource="{Binding RecipeList}" Margin=" 10" Background="#FFFAFA" >
<ListView.ContextMenu>
<ContextMenu FontSize="16" Foreground="White">
<MenuItem Header="新建配方" Name="MenuAdd" Command="{Binding CreateRecipeCommand}"></MenuItem>
<MenuItem Header="编辑配方" Name="MenuEdit"
Command="{Binding EditRecipeCommand }"
CommandParameter="{Binding PlacementTarget.SelectedIndex,RelativeSource={RelativeSource AncestorType=ContextMenu}}"></MenuItem>
<MenuItem Header="删除配方" Name="MenuDelete"
Command="{Binding DeleteRecipeCommand}"
CommandParameter="{Binding PlacementTarget.SelectedIndex,RelativeSource={RelativeSource AncestorType=ContextMenu}}"></MenuItem>
</ContextMenu>
</ListView.ContextMenu>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Margin="10"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListView>
</Grid>
</UserControl>

+ 28
- 0
BPASmart.RecipeManagement/View/RecipeManager.xaml.cs Wyświetl plik

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BPASmart.RecipeManagement.View
{
/// <summary>
/// RecipeManager.xaml 的交互逻辑
/// </summary>
public partial class RecipeManager : UserControl
{
public RecipeManager()
{
InitializeComponent();
}
}
}

+ 273
- 0
BPASmart.RecipeManagement/View/RecipesConfigure.xaml Wyświetl plik

@@ -0,0 +1,273 @@
<Window x:Class="BPASmartClient.RecipeManagement.View.RecipesConfigure"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BPASmartClient.RecipeManagement.View"
xmlns:vm="clr-namespace:BPASmart.RecipeManagement.ViewModel"
mc:Ignorable="d"
Title="RecipesConfigure" Height="600" Width="400" WindowStartupLocation="CenterScreen" WindowStyle="None" Background="White" MouseLeftButtonDown="Window_MouseLeftButtonDown">
<Window.DataContext>
<vm:RecipesConfigureViewModel/>
</Window.DataContext>
<Window.Resources>

<Style x:Key="ComboBoxStyle" TargetType="{x:Type ComboBox}">
<Setter Property="BorderThickness" Value="0" />
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="ComboBoxItem">
<Setter Property="Height" Value="25" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
<Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
<Border x:Name="_borderbg" Background="White" />

<TextBlock
x:Name="_txt"
Margin="5,0,3,0"
FontWeight="Black"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Foreground="Black"
Text="{Binding Content, RelativeSource={RelativeSource TemplatedParent}}" />

<Border
x:Name="_border"
Background="White"
Opacity="0" />
</Grid>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="false" />
<Condition Property="IsMouseOver" Value="true" />
</MultiTrigger.Conditions>
<Setter TargetName="_borderbg" Property="Background" Value="#AFEEEE" />
<Setter TargetName="_txt" Property="Foreground" Value="black" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<Grid>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.7*" />
<ColumnDefinition Width="0.3*" MaxWidth="30" />
</Grid.ColumnDefinitions>
<Border
x:Name="_prybr"
Grid.Column="0"
Grid.ColumnSpan="2"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="0" />
<ContentPresenter
x:Name="ContentSite"
Margin="3,3,0,3"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="{TemplateBinding SelectionBoxItem}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
IsHitTestVisible="False" />

<!-- ToggleButton 已数据绑定到 ComboBox 本身以切换 IsDropDownOpen -->
<ToggleButton
x:Name="ToggleButton"
Grid.Column="0"
Grid.ColumnSpan="2"
ClickMode="Press"
Focusable="false"
IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Template="{StaticResource ComboBoxToggleButton}" />
<!-- 必须将 TextBox 命名为 PART_EditableTextBox,否则 ComboBox 将无法识别它 -->
<TextBox
x:Name="PART_EditableTextBox"
Margin="2,0,0,0"
VerticalAlignment="Center"
Background="Transparent"
BorderThickness="0"
CaretBrush="{TemplateBinding Foreground}"
Focusable="True"
Foreground="{TemplateBinding Foreground}"
IsReadOnly="{TemplateBinding IsReadOnly}"
Visibility="Hidden" />

<!-- Popup 可显示 ComboBox 中的项列表。IsOpen 已数据绑定到通过 ComboBoxToggleButton 来切换的 IsDropDownOpen -->
<Popup
x:Name="Popup"
AllowsTransparency="True"
Focusable="False"
IsOpen="{TemplateBinding IsDropDownOpen}"
Placement="Bottom"
PopupAnimation="Slide">
<Grid
x:Name="DropDown"
MinWidth="{TemplateBinding ActualWidth}"
MaxHeight="150"
SnapsToDevicePixels="True">
<Border
x:Name="DropDownBorder"
BorderBrush="Black"
BorderThickness="0" />
<ScrollViewer
Margin="1"
CanContentScroll="True"
HorizontalScrollBarVisibility="Auto"
SnapsToDevicePixels="True"
VerticalScrollBarVisibility="Auto">
<!-- StackPanel 用于显示子级,方法是将 IsItemsHost 设置为 True -->
<!-- 一下可以设置列表背景色 -->
<StackPanel
Background="White"
IsItemsHost="True"
KeyboardNavigation.DirectionalNavigation="Contained" />
</ScrollViewer>
</Grid>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEditable" Value="true">
<Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="_prybr" Property="BorderBrush" Value="#aa3ba7f2" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="ContentSite" Property="Opacity" Value="0.6" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition />
<RowDefinition Height="30"/>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="103*" />
<ColumnDefinition Width="147*" />
<ColumnDefinition Width="100*" />
</Grid.ColumnDefinitions>
<TextBlock Text="配方名称:" FontSize="22"
HorizontalAlignment="Center" VerticalAlignment="Center" Height="28" Width="92"/>
<TextBox Text="{Binding RecipeName}" FontSize="20" Grid.Column="1" Width="160" Height="36"
VerticalAlignment="Center" HorizontalAlignment="Center"
VerticalContentAlignment="Center"/>
<Button Grid.Column="2"
Content="添加原料"
Foreground="White" FontSize="16" Width="90" Height="30" Margin="10" Background="#58B0ED"
Command="{Binding AddMaterailsCommand}"/>
<ScrollViewer Grid.ColumnSpan="3"
Grid.Row="1"
Margin="15,10"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Auto">
<ItemsControl ItemsSource="{Binding recipeMaterials}" >
<ItemsControl.ItemTemplate>
<DataTemplate>
<RadioButton GroupName="all">
<RadioButton.Template>
<ControlTemplate TargetType="RadioButton">
<Grid Name="gr" Height="40">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
<ColumnDefinition Width="0.5*" />
</Grid.ColumnDefinitions>

<ComboBox
Name="cb"
Grid.Column="0"
Margin="3,1"
VerticalAlignment="Center"
BorderBrush="Black"
BorderThickness="1"
FontFamily="楷体"
FontSize="20"
Foreground="Black"
IsEditable="False"
ItemsSource="{Binding DataContext.materialsName, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}"
Style="{StaticResource ComboBoxStyle}"
SelectedItem="{Binding Name}"
/>

<StackPanel
Grid.Column="1"
VerticalAlignment="Center"
Orientation="Horizontal">
<TextBox
Name="tb"
Grid.Column="1"
Width="100"
Height="29"
Margin="3,1"
VerticalAlignment="Center"
FontSize="20"
Text="{Binding MaterialWeight}" />

<TextBlock
Grid.Column="1"
Margin="0,0,8,4"
HorizontalAlignment="Right"
VerticalAlignment="Center"
FontSize="20"
Text="g" />

</StackPanel>

<Button
Grid.Column="2"
Width="70"
Height="28"
Margin="25,0,0,0"
Foreground="White"
FontSize="16"
Background="#58B0ED"
Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource AncestorType=Window, Mode=FindAncestor}}"
CommandParameter="{Binding ID}"
Content="删 除" />

</Grid>


</ControlTemplate>
</RadioButton.Template>
</RadioButton>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>

<TextBlock Text="{Binding ErrorMessage}" Grid.Row="2" Grid.ColumnSpan="3"
Foreground="Red" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<StackPanel Grid.Row="4" Grid.ColumnSpan="3" Orientation="Horizontal"
HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Content="保存" Foreground="White" FontSize="22" Width="120" Height="40" Margin="10" Background="#58B0ED"
Command="{Binding SaveCommand}"/>
<Button Content="取消" Foreground="White" FontSize="22" Width="120" Height="40" Margin="10" Background="#58B0ED"
Click="Button_Click"/>

</StackPanel>
</Grid>
</Window>

+ 37
- 0
BPASmart.RecipeManagement/View/RecipesConfigure.xaml.cs Wyświetl plik

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace BPASmartClient.RecipeManagement.View
{
/// <summary>
/// RecipesConfigure.xaml 的交互逻辑
/// </summary>
public partial class RecipesConfigure : Window
{
public RecipesConfigure()
{
InitializeComponent();
}

private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}

private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
}
}

+ 12
- 0
BPASmart.RecipeManagement/View/TechnologySetting.xaml Wyświetl plik

@@ -0,0 +1,12 @@
<UserControl x:Class="BPASmart.RecipeManagement.View.TechnologySetting"
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:BPASmart.RecipeManagement.View"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
</Grid>
</UserControl>

+ 28
- 0
BPASmart.RecipeManagement/View/TechnologySetting.xaml.cs Wyświetl plik

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BPASmart.RecipeManagement.View
{
/// <summary>
/// TechnologySetting.xaml 的交互逻辑
/// </summary>
public partial class TechnologySetting : UserControl
{
public TechnologySetting()
{
InitializeComponent();
}
}
}

+ 62
- 0
BPASmart.RecipeManagement/ViewModel/CreateOrderViewModel.cs Wyświetl plik

@@ -0,0 +1,62 @@
using BPASmart.Model.配方;
using BPASmartClient.Helper;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace BPASmart.RecipeManagement.ViewModel
{
public class CreateOrderViewModel: ObservableObject
{

public ObservableCollection<Recipes> recipes { get; set; } = new ObservableCollection<Recipes>();

public ObservableCollection<string> recipesName { get; set; } = new ObservableCollection<string>();


public RelayCommand SaveCommand { get; set; }

public RelayCommand<object> DeleteCommand { get; set; }
public RelayCommand AddRecipeCommand { get; set; }

private void Delete(object o)
{
if(o == null) return;
if(o is string id)
{
var res = recipes.FirstOrDefault(x => x.ID == id);
recipes.Remove(res);
}
}

public CreateOrderViewModel()
{
SaveCommand = new RelayCommand(() =>
{
Globle.GlobleData.orders.Add(new Order
{
OrderId = Guid.NewGuid().ToString(),
OrderdateTime = DateTime.Now.ToString(),
Recipes = recipes
});
});
DeleteCommand = new RelayCommand<object>(Delete);

AddRecipeCommand = new RelayCommand(() =>
{
recipes.Add(new Recipes() { ID = Guid.NewGuid().ToString() });
});

foreach( var item in Json<LocalRecipes>.Data.locaRecipes )
{
recipesName.Add(item.Name);
}

}

}
}

+ 1
- 0
BPASmart.RecipeManagement/ViewModel/MainWindowViewModel.cs Wyświetl plik

@@ -15,6 +15,7 @@ namespace BPASmart.RecipeManagement.ViewModel
public MainWindowViewModel()
{
Json<LocalMaterails>.Read();
Json<LocalRecipes>.Read();
}

}


+ 34
- 0
BPASmart.RecipeManagement/ViewModel/OrderManagerViewModel.cs Wyświetl plik

@@ -0,0 +1,34 @@
using BPASmart.Model.配方;
using BPASmart.RecipeManagement.View;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmart.RecipeManagement.ViewModel
{
public class OrderManagerViewModel:ObservableObject
{
/// <summary>
/// 订单集合
/// </summary>
public ObservableCollection<Order> orders { get; set; } = Globle.GlobleData.orders;

public RelayCommand CreateOrderCommand { get; set; }

public OrderManagerViewModel()
{


CreateOrderCommand = new RelayCommand(() =>
{
CreateOrder createOrder = new CreateOrder();
createOrder.ShowDialog();
});
}
}
}

+ 150
- 0
BPASmart.RecipeManagement/ViewModel/PowerManagerViewModel.cs Wyświetl plik

@@ -0,0 +1,150 @@
using BPASmart.Model.配方;
using BPASmartClient.Helper;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmart.RecipeManagement.ViewModel
{
public class PowerManagerViewModel:ObservableObject
{
public ObservableCollection<string> UserName { get; set; } = new ObservableCollection<string>();
/// <summary>
/// 全部物料
/// </summary>
public ObservableCollection<RecipeMaterials> AllMaterials { get; set; } = Json<LocalMaterails>.Data.locaMaterails;
/// <summary>
/// 用户权限物料
/// </summary>
public ObservableCollection<RecipeMaterials> UserMaterials { get; set; } = new ObservableCollection<RecipeMaterials>();
/// <summary>
/// 全部配方
/// </summary>
public ObservableCollection<Recipes> AllRecipes { get; set; } = Json<LocalRecipes>.Data.locaRecipes;
/// <summary>
/// 用户权限配方
/// </summary>
public ObservableCollection<Recipes> UserRecipes { get; set; } = new ObservableCollection<Recipes>();


public RelayCommand<object> DeleteAllCommand { get; set; }

public RelayCommand<object> AddAllCommand { get; set; }

public RelayCommand<object> AddMaterialCommand { get; set; }

public RelayCommand<object> DeleteMaterialCommand { get; set; }

public RelayCommand<object> AddRecipeCommand { get; set; }

public RelayCommand<object> DeleteRecipeCommand { get; set; }

private void DeleteAll(object o)
{
if (o == null) return;
if (o.ToString() == "Materials")
{
UserMaterials.Clear();

}
else if (o.ToString() == "Recipes")
{
UserRecipes.Clear();
}
}

private void AddAll(object o)
{
if (o == null) return;
if (o.ToString() == "Materials")
{
UserMaterials.Clear();
foreach (RecipeMaterials item in AllMaterials)
{
UserMaterials.Add(item);
}

}
else if (o.ToString() == "Recipes")
{
UserRecipes.Clear();
foreach (Recipes item in AllRecipes)
{
UserRecipes.Add(item);
}
}
}

private void AddMaterial(object o)
{
if (o == null) return;
if (o is string materail)
{
var res = AllMaterials.FirstOrDefault(p => p.Name == materail);
if (UserMaterials.FirstOrDefault(p => p.Name == res.Name) == null)
{
UserMaterials.Add(res);
}
}
}

private void DeleteMaterial(object o)
{
if (o == null) return;
if (o is string materail)
{
var res = UserMaterials.FirstOrDefault(p => p.Name == materail);
UserMaterials.Remove(res);
}
}

private void AddRecipe(object o)
{
if (o == null) return;
if (o is string materail)
{
var res = AllRecipes.FirstOrDefault(p => p.Name == materail);
if (UserRecipes.FirstOrDefault(p => p.Name == res.Name) == null)
{
UserRecipes.Add(res);
}
}
}

private void DeleteRecipe(object o)
{
if (o == null) return;
if (o is string materail)
{
var res = UserRecipes.FirstOrDefault(p => p.Name == materail);
UserRecipes.Remove(res);
}
}



public PowerManagerViewModel()
{
DeleteAllCommand = new RelayCommand<object>(DeleteAll);
AddAllCommand = new RelayCommand<object>(AddAll);
AddMaterialCommand = new RelayCommand<object>(AddMaterial);
DeleteMaterialCommand = new RelayCommand<object>(DeleteMaterial);
AddRecipeCommand = new RelayCommand<object>(AddRecipe);
DeleteRecipeCommand = new RelayCommand<object>(DeleteRecipe);


UserName.Add("admin");
UserName.Add("员工1号");
UserName.Add("员工2号");
UserName.Add("员工3号");


}
}
}

+ 60
- 0
BPASmart.RecipeManagement/ViewModel/RecipeManagerViewModel.cs Wyświetl plik

@@ -0,0 +1,60 @@
using BPASmart.Model.配方;
using BPASmartClient.Helper;
using BPASmartClient.RecipeManagement.View;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmart.RecipeManagement.ViewModel
{
public class RecipeManagerViewModel:ObservableObject
{
public ObservableCollection<Recipes> RecipeList { get; set; } = Json<LocalRecipes>.Data.locaRecipes;

public RelayCommand CreateRecipeCommand { get; set; }
public RelayCommand<object> EditRecipeCommand { get; set; }
public RelayCommand<object> DeleteRecipeCommand { get; set; }

private void EditRecipe(object o)
{
if (o == null) return;
if (o is int item && item >= 0)
{
Globle.GlobleData.ChangeRecipes = new Recipes();
Globle.GlobleData.ChangeRecipes = RecipeList[item];
RecipesConfigure recipesConfigure = new RecipesConfigure();
recipesConfigure.ShowDialog();
}
}

private void DeleteRecipe(object o)
{
if (o == null) return;
if (o is int i && i >= 0)
{
RecipeList.RemoveAt(i);
Json<LocalRecipes>.Save();
}
}

public RecipeManagerViewModel()
{
CreateRecipeCommand = new RelayCommand(() =>
{
Globle.GlobleData.ChangeRecipes = null;
RecipesConfigure recipesConfigure = new RecipesConfigure();
recipesConfigure.ShowDialog();
});

EditRecipeCommand = new RelayCommand<object>(EditRecipe);

DeleteRecipeCommand = new RelayCommand<object>(DeleteRecipe);

}
}
}

+ 115
- 0
BPASmart.RecipeManagement/ViewModel/RecipesConfigureViewModel.cs Wyświetl plik

@@ -0,0 +1,115 @@
using BPASmart.Model.配方;
using BPASmartClient.Helper;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmart.RecipeManagement.ViewModel
{
public class RecipesConfigureViewModel:ObservableObject
{
public ObservableCollection<RecipeMaterials> recipeMaterials { get; set; } = new ObservableCollection<RecipeMaterials>();

/// <summary>
/// 原料名称集合
/// </summary>
public ObservableCollection<string> materialsName { get; set; } = new ObservableCollection<string>();

/// <summary>
/// 配方名称
/// </summary>
public string RecipeName { get { return _repiceName; } set { _repiceName = value; OnPropertyChanged(); } }
private string _repiceName;



public string ErrorMessage { get { return _errorMessage; } set { _errorMessage = value; OnPropertyChanged(); } }
private string _errorMessage;

public RelayCommand AddMaterailsCommand { get; set; }

public RelayCommand SaveCommand { get; set; }

public RelayCommand<object> DeleteCommand { get; set; }
private void Delete(object o)
{
if (o == null) return;
if(o is string id)
{
var res = recipeMaterials.FirstOrDefault(p=>p.ID == id);
if (res != null) recipeMaterials.Remove(res);
}
}

public RecipesConfigureViewModel()
{


AddMaterailsCommand = new RelayCommand(() =>
{
recipeMaterials.Add(new RecipeMaterials()
{
ID = Guid.NewGuid().ToString()
});
});


SaveCommand = new RelayCommand(() =>
{
if(RecipeName == null)
{
ErrorMessage = "配方名称为空";
return;
}
if (Globle.GlobleData.ChangeRecipes!=null)
{
var res = Json<LocalRecipes>.Data.locaRecipes.FirstOrDefault(p => p.ID == Globle.GlobleData.ChangeRecipes.ID);
res.recipeMaterials = recipeMaterials;
res.Name = RecipeName;
}
else
{
var res = Json<LocalRecipes>.Data.locaRecipes.FirstOrDefault(p => p.Name == RecipeName);
if (res != null)
{
ErrorMessage = "配方名称已存在";
return;
}
Json<LocalRecipes>.Data.locaRecipes.Add(new Recipes
{
ID = Guid.NewGuid().ToString() ,
Name = RecipeName,
recipeMaterials = recipeMaterials
});
}
Json<LocalRecipes>.Save();
});

DeleteCommand = new RelayCommand<object>(Delete);

if (Json<LocalMaterails>.Data.locaMaterails.Count > 0)
{
foreach (var materail in Json<LocalMaterails>.Data.locaMaterails)
{
materialsName.Add(materail.Name);
}
}
if(Globle.GlobleData.ChangeRecipes != null)
{
RecipeName = Globle.GlobleData.ChangeRecipes.Name.ToString();

recipeMaterials = Globle.GlobleData.ChangeRecipes.recipeMaterials;
}
}
}
}

+ 196
- 196
BPASmart.Server/CommunicationServer.cs Wyświetl plik

@@ -34,83 +34,83 @@ namespace BPASmart.Server
CommunicationDevices.TryAdd(item.DeviceName, modbusTcpMaster);
ThreadManage.GetInstance().StartLong(new Action(() =>
{
GetReadDataModels(item).ToList()?.ForEach(temp =>
{
//switch (temp.Key)
//{
// case EDataType.Bool:
// temp.Value?.ForEach(value =>
// {
// //var res = modbusTcpMaster.ReadBool(value.StartAddress.ToString(), value.Length);
// var res = modbusTcpMaster.Read<bool[]>(value.StartAddress.ToString(), value.Length);
// SetValue(res.Content, item.DeviceName, value, 1);
// });
// break;
// case EDataType.Byte:
// break;
// case EDataType.Int:
// break;
// case EDataType.Word:
// temp.Value?.ForEach(value =>
// {
// //var res = modbusTcpMaster.ReadUshort(value.StartAddress.ToString(), value.Length);
// var res = modbusTcpMaster.Read<ushort[]>(value.StartAddress.ToString(), value.Length);
// SetValue(res.Content, item.DeviceName, value, 1);
// });
// break;
// case EDataType.Dint:
// break;
// case EDataType.Dword:
// temp.Value?.ForEach(value =>
// {
// //var res = modbusTcpMaster.ReadUint(value.StartAddress.ToString(), value.Length);
// var res = modbusTcpMaster.Read<uint[]>(value.StartAddress.ToString(), value.Length);
// SetValue(res.Content, item.DeviceName, value, 2);
// });
// break;
// case EDataType.Float:
// temp.Value?.ForEach(value =>
// {
// //var res = modbusTcpMaster.ReadFloat(value.StartAddress.ToString(), value.Length);
// var res = modbusTcpMaster.Read<float[]>(value.StartAddress.ToString(), value.Length);
// SetValue(res.Content, item.DeviceName, value, 2);
// });
// break;
// default:
// break;
//}
item.VarTableModels.GetReadDataModels().ToList()?.ForEach(temp =>
{
//switch (temp.Key)
//{
// case EDataType.Bool:
// temp.Value?.ForEach(value =>
// {
// //var res = modbusTcpMaster.ReadBool(value.StartAddress.ToString(), value.Length);
// var res = modbusTcpMaster.Read<bool[]>(value.StartAddress.ToString(), value.Length);
// SetValue(res.Content, item.DeviceName, value, 1);
// });
// break;
// case EDataType.Byte:
// break;
// case EDataType.Int:
// break;
// case EDataType.Word:
// temp.Value?.ForEach(value =>
// {
// //var res = modbusTcpMaster.ReadUshort(value.StartAddress.ToString(), value.Length);
// var res = modbusTcpMaster.Read<ushort[]>(value.StartAddress.ToString(), value.Length);
// SetValue(res.Content, item.DeviceName, value, 1);
// });
// break;
// case EDataType.Dint:
// break;
// case EDataType.Dword:
// temp.Value?.ForEach(value =>
// {
// //var res = modbusTcpMaster.ReadUint(value.StartAddress.ToString(), value.Length);
// var res = modbusTcpMaster.Read<uint[]>(value.StartAddress.ToString(), value.Length);
// SetValue(res.Content, item.DeviceName, value, 2);
// });
// break;
// case EDataType.Float:
// temp.Value?.ForEach(value =>
// {
// //var res = modbusTcpMaster.ReadFloat(value.StartAddress.ToString(), value.Length);
// var res = modbusTcpMaster.Read<float[]>(value.StartAddress.ToString(), value.Length);
// SetValue(res.Content, item.DeviceName, value, 2);
// });
// break;
// default:
// break;
//}

Array ResultArray = null;
temp.Value?.ForEach(value =>
{
switch (temp.Key)
{
case EDataType.Bool:
ResultArray = modbusTcpMaster.Read<bool[]>(value.StartAddress.ToString(), value.Length)?.Content;
break;
case EDataType.Byte:
break;
case EDataType.Int:
ResultArray = modbusTcpMaster.Read<short[]>(value.StartAddress.ToString(), value.Length)?.Content;
break;
case EDataType.Word:
ResultArray = modbusTcpMaster.Read<ushort[]>(value.StartAddress.ToString(), value.Length)?.Content;
break;
case EDataType.Dint:
ResultArray = modbusTcpMaster.Read<int[]>(value.StartAddress.ToString(), value.Length)?.Content;
break;
case EDataType.Dword:
ResultArray = modbusTcpMaster.Read<uint[]>(value.StartAddress.ToString(), value.Length)?.Content;
break;
case EDataType.Float:
ResultArray = modbusTcpMaster.Read<float[]>(value.StartAddress.ToString(), value.Length)?.Content;
break;
default:
break;
}
SetValue(ResultArray, item.DeviceName, value, temp.Key);
});
});
Array ResultArray = null;
temp.Value?.ForEach(value =>
{
switch (temp.Key)
{
case EDataType.Bool:
ResultArray = modbusTcpMaster.Read<bool[]>(value.StartAddress.ToString(), value.Length)?.Content;
break;
case EDataType.Byte:
break;
case EDataType.Int:
ResultArray = modbusTcpMaster.Read<short[]>(value.StartAddress.ToString(), value.Length)?.Content;
break;
case EDataType.Word:
ResultArray = modbusTcpMaster.Read<ushort[]>(value.StartAddress.ToString(), value.Length)?.Content;
break;
case EDataType.Dint:
ResultArray = modbusTcpMaster.Read<int[]>(value.StartAddress.ToString(), value.Length)?.Content;
break;
case EDataType.Dword:
ResultArray = modbusTcpMaster.Read<uint[]>(value.StartAddress.ToString(), value.Length)?.Content;
break;
case EDataType.Float:
ResultArray = modbusTcpMaster.Read<float[]>(value.StartAddress.ToString(), value.Length)?.Content;
break;
default:
break;
}
SetValue(ResultArray, item.DeviceName, value, temp.Key);
});
});

Thread.Sleep(100);
}), $"{item.DeviceName} 设备数据采集");
@@ -213,69 +213,69 @@ namespace BPASmart.Server
}
}

private void SetValue<TArray>(TArray[] arrays, string DeviceName, ReadDataModel readDataModel, ushort by)
{
if (arrays != null)
{
int index = Array.FindIndex(Json<CommunicationPar>.Data.CommunicationDevices.ToArray(), p => p.DeviceName == DeviceName);//获取设备所在集合位置
if (index >= 0 && index < Json<CommunicationPar>.Data.CommunicationDevices.Count)
{
var tempArray = Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(index).VarTableModels.ToArray();
for (int i = 0; i < arrays.Length; i++)
{
int varIndex = Array.FindIndex(tempArray, p => p.RealAddress == (readDataModel.StartAddress + (i * by)).ToString());
if (varIndex >= 0 && varIndex < tempArray.Length)
{
Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(index).VarTableModels.ElementAt(varIndex).CurrentValue = arrays[i].ToString();
}
}
var Devicename = Json<CommunicationPar>.Data.CommunicationDevices[index].DeviceName;
List<ReeisDataModel> reeisDataModels = new List<ReeisDataModel>();
Json<CommunicationPar>.Data.CommunicationDevices[index].VarTableModels.ToList().ForEach(tempVar =>
{
if (tempVar.VarName.Length > 0)
{
reeisDataModels.Add(new ReeisDataModel()
{
VarName = tempVar.VarName,
VarVaule = tempVar.CurrentValue,
DataType = (EDataType)Enum.Parse(typeof(EDataType), tempVar.DataType)
});
}
});
RedisHelper.GetInstance.SetValue($"{Devicename}", reeisDataModels);
}
}
}
//private void SetValue<TArray>(TArray[] arrays, string DeviceName, ReadDataModel readDataModel, ushort by)
//{
// if (arrays != null)
// {
// int index = Array.FindIndex(Json<CommunicationPar>.Data.CommunicationDevices.ToArray(), p => p.DeviceName == DeviceName);//获取设备所在集合位置
// if (index >= 0 && index < Json<CommunicationPar>.Data.CommunicationDevices.Count)
// {
// var tempArray = Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(index).VarTableModels.ToArray();
// for (int i = 0; i < arrays.Length; i++)
// {
// int varIndex = Array.FindIndex(tempArray, p => p.RealAddress == (readDataModel.StartAddress + (i * by)).ToString());
// if (varIndex >= 0 && varIndex < tempArray.Length)
// {
// Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(index).VarTableModels.ElementAt(varIndex).CurrentValue = arrays[i].ToString();
// }
// }
// var Devicename = Json<CommunicationPar>.Data.CommunicationDevices[index].DeviceName;
// List<ReeisDataModel> reeisDataModels = new List<ReeisDataModel>();
// Json<CommunicationPar>.Data.CommunicationDevices[index].VarTableModels.ToList().ForEach(tempVar =>
// {
// if (tempVar.VarName.Length > 0)
// {
// reeisDataModels.Add(new ReeisDataModel()
// {
// VarName = tempVar.VarName,
// VarVaule = tempVar.CurrentValue,
// DataType = (EDataType)Enum.Parse(typeof(EDataType), tempVar.DataType)
// });
// }
// });
// RedisHelper.GetInstance.SetValue($"{Devicename}", reeisDataModels);
// }
// }
//}

private ushort GetBySize(EDataType eDataType)
{
switch (eDataType)
{
case EDataType.Bool:
case EDataType.Byte:
case EDataType.Int:
case EDataType.Word:
return 1;
case EDataType.Dint:
case EDataType.Dword:
case EDataType.Float:
return 2;
case EDataType.Double:
break;
case EDataType.String:
break;
default:
break;
}
return 1;
}
//private ushort GetBySize(EDataType eDataType)
//{
// switch (eDataType)
// {
// case EDataType.Bool:
// case EDataType.Byte:
// case EDataType.Int:
// case EDataType.Word:
// return 1;
// case EDataType.Dint:
// case EDataType.Dword:
// case EDataType.Float:
// return 2;
// case EDataType.Double:
// break;
// case EDataType.String:
// break;
// default:
// break;
// }
// return 1;
//}

private void SetValue(Array arrays, string DeviceName, ReadDataModel readDataModel, EDataType eDataType)
{
if (arrays != null)
{
ushort by = GetBySize(eDataType);
ushort by = eDataType.GetEDataSize();
int index = Array.FindIndex(Json<CommunicationPar>.Data.CommunicationDevices.ToArray(), p => p.DeviceName == DeviceName);//获取设备所在集合位置
if (index >= 0 && index < Json<CommunicationPar>.Data.CommunicationDevices.Count)
{
@@ -309,70 +309,70 @@ namespace BPASmart.Server



private Dictionary<EDataType, List<ReadDataModel>> GetReadDataModels(CommunicationModel communicationModel)
{
Dictionary<EDataType, List<ReadDataModel>> readDataModels = new Dictionary<EDataType, List<ReadDataModel>>();
communicationModel.VarTableModels.GroupBy(p => p.DataType)?.ToList()?.ForEach(tempVar =>
{
if (tempVar.Key != null && tempVar.Key.Length > 0)
{
//int address = tempVar.Min(p => p.RealAddress);
EDataType dataType = (EDataType)Enum.Parse(typeof(EDataType), tempVar.Key);
switch (dataType)
{
case EDataType.Bool:
case EDataType.Byte:
case EDataType.Int:
case EDataType.Word:
if (!readDataModels.ContainsKey(dataType)) readDataModels.TryAdd(dataType, GetDataGroup(tempVar));
break;
case EDataType.Dint:
case EDataType.Dword:
case EDataType.Float:
if (!readDataModels.ContainsKey(dataType)) readDataModels.TryAdd(dataType, GetDataGroup(tempVar, 2));
break;
default:
break;
}
}
});
return readDataModels;
}
//private Dictionary<EDataType, List<ReadDataModel>> GetReadDataModels(CommunicationModel communicationModel)
//{
// Dictionary<EDataType, List<ReadDataModel>> readDataModels = new Dictionary<EDataType, List<ReadDataModel>>();
// communicationModel.VarTableModels.GroupBy(p => p.DataType)?.ToList()?.ForEach(tempVar =>
// {
// if (tempVar.Key != null && tempVar.Key.Length > 0)
// {
// //int address = tempVar.Min(p => p.RealAddress);
// EDataType dataType = (EDataType)Enum.Parse(typeof(EDataType), tempVar.Key);
// switch (dataType)
// {
// case EDataType.Bool:
// case EDataType.Byte:
// case EDataType.Int:
// case EDataType.Word:
// if (!readDataModels.ContainsKey(dataType)) readDataModels.TryAdd(dataType, GetDataGroup(tempVar));
// break;
// case EDataType.Dint:
// case EDataType.Dword:
// case EDataType.Float:
// if (!readDataModels.ContainsKey(dataType)) readDataModels.TryAdd(dataType, GetDataGroup(tempVar, 2));
// break;
// default:
// break;
// }
// }
// });
// return readDataModels;
//}

private List<ReadDataModel> GetDataGroup(IGrouping<string, VariableInfo> variableInfos, int by = 1)
{
List<ReadDataModel> ReturnValue = new List<ReadDataModel>();
var res = variableInfos?.OrderBy(p => p.RealAddress).ToList();
List<int> RealAddresss = new List<int>();
variableInfos.ToList()?.ForEach(item => { if (int.TryParse(item.RealAddress, out int add)) RealAddresss.Add(add); });
int count = 0;
if (res != null)
{
//int address = variableInfos.Min(p => p.RealAddress);
int address = RealAddresss.Min();
int startAddress = address;
for (int i = 0; i < res.Count; i++)
{
if (int.TryParse(res.ElementAt(i).RealAddress, out int TempAddress))
{
if (TempAddress == address)
{
count++;
address += by;
}
else
{
ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count });
count = 1;
address = TempAddress + by;
startAddress = TempAddress;
}
}
//private List<ReadDataModel> GetDataGroup(IGrouping<string, VariableInfo> variableInfos, int by = 1)
//{
// List<ReadDataModel> ReturnValue = new List<ReadDataModel>();
// var res = variableInfos?.OrderBy(p => p.RealAddress).ToList();
// List<int> RealAddresss = new List<int>();
// variableInfos.ToList()?.ForEach(item => { if (int.TryParse(item.RealAddress, out int add)) RealAddresss.Add(add); });
// int count = 0;
// if (res != null)
// {
// //int address = variableInfos.Min(p => p.RealAddress);
// int address = RealAddresss.Min();
// int startAddress = address;
// for (int i = 0; i < res.Count; i++)
// {
// if (int.TryParse(res.ElementAt(i).RealAddress, out int TempAddress))
// {
// if (TempAddress == address)
// {
// count++;
// address += by;
// }
// else
// {
// ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count });
// count = 1;
// address = TempAddress + by;
// startAddress = TempAddress;
// }
// }

}
ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count });
}
return ReturnValue;
}
// }
// ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count });
// }
// return ReturnValue;
//}
}
}

+ 169
- 156
BPASmart.VariableManager/ViewModels/VariableConfigViewModel.cs Wyświetl plik

@@ -27,32 +27,33 @@ namespace BPASmart.VariableManager.ViewModels
{
DataInit(o);
VarNameChanged();
DelegationNotifi.GetInstance.VariableSave = new Action(() => { Json<CommunicationPar>.Save(); });
StartMotionCommand = new RelayCommand(() =>
{
switch (ButtonContext)
{
case "开始监控":
TabName = "当前值";
CurrentVisibility = Visibility.Visible;
RemoveButVisiblity = Visibility.Collapsed;
ButtonContext = "停止监控";
IsEnable = false;
Motion();
break;
case "停止监控":
TabName = "操作";
CurrentVisibility = Visibility.Collapsed;
RemoveButVisiblity = Visibility.Visible;
ButtonContext = "开始监控";
IsEnable = true;
ThreadManage.GetInstance().StopTask($"{DeviceType} 初始化连接");
ThreadManage.GetInstance().StopTask($"{DeviceType} 设备数据采集");
break;
default:
break;
}
});
{
switch (ButtonContext)
{
case "开始监控":
TabName = "当前值";
CurrentVisibility = Visibility.Visible;
RemoveButVisiblity = Visibility.Collapsed;
ButtonContext = "停止监控";
IsEnable = false;
Motion();
break;
case "停止监控":
TabName = "操作";
CurrentVisibility = Visibility.Collapsed;
RemoveButVisiblity = Visibility.Visible;
ButtonContext = "开始监控";
IsEnable = true;
ThreadManage.GetInstance().StopTask($"{DeviceType} 初始化连接");
ThreadManage.GetInstance().StopTask($"{DeviceType} 设备数据采集");
break;
default:
break;
}
});

RemoveCommand = new RelayCommand<object>((o) =>
{
@@ -157,52 +158,42 @@ namespace BPASmart.VariableManager.ViewModels
{
ThreadManage.GetInstance().StartLong(new Action(() =>
{
GetReadDataModels().ToList()?.ForEach(temp =>
varialeInfos.GetReadDataModels().ToList()?.ForEach(temp =>
{
switch (temp.Key)
Array ResultArray = null;
temp.Value?.ForEach(value =>
{
case EDataType.Bool:
temp.Value?.ForEach(value =>
{
var res = modbusTcpMaster.ReadCoils(value.StartAddress, value.Length);
SetValue(res, value, 1);
});
break;
case EDataType.Byte:
break;
case EDataType.Int:
break;
case EDataType.Word:
temp.Value?.ForEach(value =>
{
var res = modbusTcpMaster.ReadHoldingRegisters(value.StartAddress, value.Length);
SetValue(res, value, 1);
});
break;
case EDataType.Dint:
break;
case EDataType.Dword:
temp.Value?.ForEach(value =>
{
var res = modbusTcpMaster.ReadHoldingRegisters(value.StartAddress, value.Length);
SetValue(res, value, 2);
});
break;
case EDataType.Float:
temp.Value?.ForEach(value =>
{
var res = modbusTcpMaster.ReadHoldingRegisters(value.StartAddress, value.Length);
SetValue(res, value, 2);
});
break;
default:
break;
}
switch (temp.Key)
{
case EDataType.Bool:
ResultArray = modbusTcpMaster.Read<bool[]>(value.StartAddress.ToString(), value.Length)?.Content;
break;
case EDataType.Byte:
break;
case EDataType.Int:
ResultArray = modbusTcpMaster.Read<short[]>(value.StartAddress.ToString(), value.Length)?.Content;
break;
case EDataType.Word:
ResultArray = modbusTcpMaster.Read<ushort[]>(value.StartAddress.ToString(), value.Length)?.Content;
break;
case EDataType.Dint:
ResultArray = modbusTcpMaster.Read<int[]>(value.StartAddress.ToString(), value.Length)?.Content;
break;
case EDataType.Dword:
ResultArray = modbusTcpMaster.Read<uint[]>(value.StartAddress.ToString(), value.Length)?.Content;
break;
case EDataType.Float:
ResultArray = modbusTcpMaster.Read<float[]>(value.StartAddress.ToString(), value.Length)?.Content;
break;
default:
break;
}
SetValue(ResultArray, value, temp.Key);
});
});

Thread.Sleep(100);
}), $"{DeviceType} 设备数据采集");
//var DeviceModel = item;
});
modbusTcpMaster.IsReconnect = true;
modbusTcpMaster.ModbusTcpConnect(_modbusTcp.IP, _modbusTcp.PortNum);
@@ -284,109 +275,131 @@ namespace BPASmart.VariableManager.ViewModels
public RelayCommand<object> RemoveCommand { get; set; }
#endregion

private void SetValue<TArray>(TArray[] arrays, ReadDataModel readDataModel, ushort by)
{
for (int i = 0; i < arrays.Length; i++)
{
int varIndex = Array.FindIndex(varialeInfos.ToArray(), p => p.RealAddress == (readDataModel.StartAddress + (i * by)).ToString());
if (varIndex >= 0 && varIndex < varialeInfos.Count)
{
varialeInfos.ElementAt(varIndex).CurrentValue = arrays[i].ToString();
}
}
}
//private void SetValue<TArray>(TArray[] arrays, ReadDataModel readDataModel, ushort by)
//{
// for (int i = 0; i < arrays.Length; i++)
// {
// int varIndex = Array.FindIndex(varialeInfos.ToArray(), p => p.RealAddress == (readDataModel.StartAddress + (i * by)).ToString());
// if (varIndex >= 0 && varIndex < varialeInfos.Count)
// {
// varialeInfos.ElementAt(varIndex).CurrentValue = arrays[i].ToString();
// }
// }

private Dictionary<EDataType, List<ReadDataModel>> GetReadDataModels()
//}

private void SetValue(Array arrays, ReadDataModel readDataModel, EDataType eDataType)
{
Dictionary<EDataType, List<ReadDataModel>> readDataModels = new Dictionary<EDataType, List<ReadDataModel>>();
varialeInfos.GroupBy(p => p.DataType)?.ToList()?.ForEach(tempVar =>
if (arrays != null)
{
if (tempVar.Key != null && tempVar.Key.Length > 0)
ushort by = eDataType.GetEDataSize();
for (int i = 0; i < arrays.Length; i++)
{
//int address = tempVar.Min(p => p.RealAddress);
EDataType dataType = (EDataType)Enum.Parse(typeof(EDataType), tempVar.Key);
switch (dataType)
int varIndex = Array.FindIndex(varialeInfos.ToArray(), p => p.RealAddress == (readDataModel.StartAddress + (i * by)).ToString());
if (varIndex >= 0 && varIndex < varialeInfos.Count)
{
case EDataType.Bool:
case EDataType.Byte:
case EDataType.Int:
case EDataType.Word:
if (!readDataModels.ContainsKey(dataType)) readDataModels.TryAdd(dataType, GetDataGroup(tempVar));
break;
case EDataType.Dint:
case EDataType.Dword:
case EDataType.Float:
if (!readDataModels.ContainsKey(dataType)) readDataModels.TryAdd(dataType, GetDataGroup(tempVar, 2));
break;
default:
break;
varialeInfos.ElementAt(varIndex).CurrentValue = arrays.GetValue(i)?.ToString();
}
}
});
return readDataModels;
}

private List<ReadDataModel> GetDataGroup(IGrouping<string, VariableInfo> variableInfos, int by = 1)
{
//List<ReadDataModel> ReturnValue = new List<ReadDataModel>();
//var res = variableInfos?.OrderBy(p => p.RealAddress).ToList();
//int count = 0;
//if (res != null)
//{
// int address = variableInfos.Min(p => p.RealAddress);
// int startAddress = address;
// for (int i = 0; i < res.Count; i++)
// {
// if (res.ElementAt(i).RealAddress == address)
// {
// count++;
// address += by;
// }
// else
// {
// ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count });
// count = 1;
// address = res.ElementAt(i).RealAddress + by;
// startAddress = res.ElementAt(i).RealAddress;
// }
// }
// ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count });
//}
//return ReturnValue;

List<ReadDataModel> ReturnValue = new List<ReadDataModel>();
var res = variableInfos?.OrderBy(p => p.RealAddress).ToList();
List<int> RealAddresss = new List<int>();
variableInfos.ToList()?.ForEach(item => { if (int.TryParse(item.RealAddress, out int add)) RealAddresss.Add(add); });
int count = 0;
if (res != null)
{
int address = RealAddresss.Min();
int startAddress = address;
for (int i = 0; i < res.Count; i++)
{
if (int.TryParse(res.ElementAt(i).RealAddress, out int TempAddress))
{
if (TempAddress == address)
{
count++;
address += by;
}
else
{
ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count });
count = 1;
address = TempAddress + by;
startAddress = TempAddress;
}
}

}
ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count });


//int index = Array.FindIndex(Json<CommunicationPar>.Data.CommunicationDevices.ToArray(), p => p.DeviceName == DeviceName);//获取设备所在集合位置
//if (index >= 0 && index < Json<CommunicationPar>.Data.CommunicationDevices.Count)
//{
// var tempArray = Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(index).VarTableModels.ToArray();
// for (int i = 0; i < arrays.Length; i++)
// {
// int varIndex = Array.FindIndex(tempArray, p => p.RealAddress == (readDataModel.StartAddress + (i * by)).ToString());
// if (varIndex >= 0 && varIndex < tempArray.Length)
// {
// Json<CommunicationPar>.Data.CommunicationDevices.ElementAt(index).VarTableModels.ElementAt(varIndex).CurrentValue = arrays.GetValue(i)?.ToString();
// }
// }
// var Devicename = Json<CommunicationPar>.Data.CommunicationDevices[index].DeviceName;
// List<ReeisDataModel> reeisDataModels = new List<ReeisDataModel>();
// Json<CommunicationPar>.Data.CommunicationDevices[index].VarTableModels.ToList().ForEach(tempVar =>
// {
// if (tempVar.VarName.Length > 0)
// {
// reeisDataModels.Add(new ReeisDataModel()
// {
// VarName = tempVar.VarName,
// VarVaule = tempVar.CurrentValue,
// DataType = (EDataType)Enum.Parse(typeof(EDataType), tempVar.DataType)
// });
// }
// });
// RedisHelper.GetInstance.SetValue($"{Devicename}", reeisDataModels);
//}
}
return ReturnValue;
}

//private Dictionary<EDataType, List<ReadDataModel>> GetReadDataModels()
//{
// Dictionary<EDataType, List<ReadDataModel>> readDataModels = new Dictionary<EDataType, List<ReadDataModel>>();
// varialeInfos.GroupBy(p => p.DataType)?.ToList()?.ForEach(tempVar =>
// {
// if (tempVar.Key != null && tempVar.Key.Length > 0)
// {
// EDataType dataType = (EDataType)Enum.Parse(typeof(EDataType), tempVar.Key);
// switch (dataType)
// {
// case EDataType.Bool:
// case EDataType.Byte:
// case EDataType.Int:
// case EDataType.Word:
// if (!readDataModels.ContainsKey(dataType)) readDataModels.TryAdd(dataType, GetDataGroup(tempVar));
// break;
// case EDataType.Dint:
// case EDataType.Dword:
// case EDataType.Float:
// if (!readDataModels.ContainsKey(dataType)) readDataModels.TryAdd(dataType, GetDataGroup(tempVar, 2));
// break;
// default:
// break;
// }
// }
// });
// return readDataModels;
//}

//private List<ReadDataModel> GetDataGroup(IGrouping<string, VariableInfo> variableInfos, int by = 1)
//{
// List<ReadDataModel> ReturnValue = new List<ReadDataModel>();
// var res = variableInfos?.OrderBy(p => p.RealAddress).ToList();
// List<int> RealAddresss = new List<int>();
// variableInfos.ToList()?.ForEach(item => { if (int.TryParse(item.RealAddress, out int add)) RealAddresss.Add(add); });
// int count = 0;
// if (res != null)
// {
// int address = RealAddresss.Min();
// int startAddress = address;
// for (int i = 0; i < res.Count; i++)
// {
// if (int.TryParse(res.ElementAt(i).RealAddress, out int TempAddress))
// {
// if (TempAddress == address)
// {
// count++;
// address += by;
// }
// else
// {
// ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count });
// count = 1;
// address = TempAddress + by;
// startAddress = TempAddress;
// }
// }

// }
// ReturnValue.Add(new ReadDataModel() { StartAddress = (ushort)startAddress, Length = (ushort)count });
// }
// return ReturnValue;
//}



/// <summary>


+ 3
- 1
BPASmart.VariableManager/Views/VariableConfig.xaml Wyświetl plik

@@ -248,7 +248,7 @@
<!--#endregion-->

<Grid Grid.Row="2">
<ScrollViewer IsEnabled="{Binding IsEnable}" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
<ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
<ItemsControl ItemsSource="{Binding varialeInfos}">
<ItemsControl.ItemTemplate>
<DataTemplate>
@@ -274,6 +274,7 @@

<Grid Grid.Column="1" KeyDown="TextBox_KeyDown">
<TextBox
IsEnabled="{Binding DataContext.IsEnable, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}"
Width="{Binding DataContext.NameWidth, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}"
Foreground="{Binding IsRedundant, Converter={StaticResource tabConvert}}"
Style="{StaticResource InputTextboxStyle}"
@@ -287,6 +288,7 @@

<TextBox
Grid.Column="2"
IsEnabled="{Binding DataContext.IsEnable, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}"
KeyDown="TextBox_KeyDown"
Width="{Binding DataContext.AddressWidth, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}"
Foreground="{Binding IsRedundant, Converter={StaticResource tabConvert}}"


+ 1
- 1
BPASmartClient.SCADAControl/CustomerControls/TheRadioButton.cs Wyświetl plik

@@ -26,7 +26,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls
ResourceDictionary languageResDic = new ResourceDictionary();
languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml",UriKind.RelativeOrAbsolute);
this.Resources.MergedDictionaries.Add(languageResDic);
SetCurrentValue(ContentProperty, "单选按钮");
//SetCurrentValue(ContentProperty, "单选按钮");
}
static TheRadioButton()
{


+ 93
- 0
BeDesignerSCADA/Converters/BrowsableAttribute.cs Wyświetl plik

@@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BeDesignerSCADA.Converters
{
//
// 摘要:
// Specifies whether a property or event should be displayed in a Properties window.
[AttributeUsage(AttributeTargets.All)]
public class BrowsableAttribute :Attribute
{
//
// 摘要:
// Specifies the default value for the System.ComponentModel.BrowsableAttribute,
// which is System.ComponentModel.BrowsableAttribute.Yes. This static field is read-only.
public static BrowsableAttribute Default;

//
// 摘要:
// Specifies that a property or event cannot be modified at design time. This static
// field is read-only.
public static BrowsableAttribute No;

//
// 摘要:
// Specifies that a property or event can be modified at design time. This static
// field is read-only.
public static BrowsableAttribute Yes;

//
// 摘要:
// Gets a value indicating whether an object is browsable.
//
// 返回结果:
// true if the object is browsable; otherwise, false.
public bool Browsable { get; set; }

//
// 摘要:
// Initializes a new instance of the System.ComponentModel.BrowsableAttribute class.
//
// 参数:
// browsable:
// true if a property or event can be modified at design time; otherwise, false.
// The default is true.
public BrowsableAttribute(bool browsable)
{
this.Browsable = browsable;
}

//
// 摘要:
// Indicates whether this instance and a specified object are equal.
//
// 参数:
// obj:
// Another object to compare to.
//
// 返回结果:
// true if obj is equal to this instance; otherwise, false.
public override bool Equals([NotNullWhen(true)] object? obj)
{
throw null;
}

//
// 摘要:
// Returns the hash code for this instance.
//
// 返回结果:
// A 32-bit signed integer hash code.
public override int GetHashCode()
{
throw null;
}

//
// 摘要:
// Determines if this attribute is the default.
//
// 返回结果:
// true if the attribute is the default value for this attribute class; otherwise,
// false.
public override bool IsDefaultAttribute()
{
throw null;
}
}
}

+ 58
- 51
BeDesignerSCADA/ViewModel/MainViewModel.cs Wyświetl plik

@@ -274,55 +274,52 @@ namespace BeDesignerSCADA.ViewModel
{ "Code" , "代码过滤脚本"},
{ "GenerateData" , "数据结果"},
};
//{"EventSendNameList" , "发送事件集"}
/// <summary>
/// 数据刷新
/// </summary>
public void DataSX()
{
//if (CanSelectedItem is System.Windows.Controls.Control)
{
//属性变量
PropertyGridCommand cmd = new PropertyGridCommand();
var content = CanSelectedItem;// as System.Windows.Controls.Control;
if (content is IExecutable executable)
executable.PropertyChange += Executable_PropertyChange;
//属性变量
PropertyGridCommand cmd = new PropertyGridCommand();
var content = CanSelectedItem;// as System.Windows.Controls.Control;
if (content is IExecutable executable)
executable.PropertyChange += Executable_PropertyChange;

foreach (var item in EventName)
foreach (var item in EventName)
{
System.Reflection.PropertyInfo info = content.GetType().GetProperty(item.Key);
var propName = info?.GetValue(content,null);
if (info != null && (item.Key == "Content" ? (propName is string) : true))
{
System.Reflection.PropertyInfo info = content.GetType().GetProperty(item.Key);
var propName = info?.GetValue(content,null);
if (info != null && item.Key == "Content" ? (propName is string) : true)
{
//var taget = this.GetType().GetMembers().Where(t => t.Name.Equals("BrowsableTrue")).FirstOrDefault();
//var datas= CustomAttributeData.GetCustomAttributes(taget)[0];
//cmd.GetType().GetProperty(item.Value).CustomAttributes.Append(datas);
cmd.GetType().GetProperty(item.Value).SetValue(cmd,propName);
}
SetPropertyVisibility(cmd,item.Value,true);
cmd.GetType().GetProperty(item.Value).SetValue(cmd,propName);
}
else
{
SetPropertyVisibility(cmd,item.Value,false);
}
cmd.PropertyChanged += Cmd_PropertyChanged;
PropeObject = cmd;
}
cmd.PropertyChanged += Cmd_PropertyChanged;
PropeObject = null;
PropeObject = cmd;
}

/// <summary>
/// 内部属性变化通知
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Executable_PropertyChange(object? sender,EventArgs e)
{
System.Windows.Controls.Control content = CanSelectedItem as System.Windows.Controls.Control;
System.Reflection.PropertyInfo info = content.GetType().GetProperty("GenerateData");
var propName = info?.GetValue(content,null);
PropeObject.GetType().GetProperty("数据结果").SetValue(PropeObject,propName);
DevNameList = new System.Collections.ObjectModel.ObservableCollection<string>();
DevValueList = new System.Collections.ObjectModel.ObservableCollection<string>();
Class_DataBus.GetInstance().Dic_DeviceData.Keys?.ToList().ForEach(key => { DevNameList.Add(key); });
}

[Browsable(true)]
public void BrowsableTrue() { }
[Browsable(false)]
public void BrowsableFalse() { }

/// <summary>
/// 修改属性后
/// </summary>
@@ -377,36 +374,46 @@ namespace BeDesignerSCADA.ViewModel
}
#endregion

#region 设置
#region 特性控制
/// <summary>
/// 设置Browsable特性的值
/// 通过反射控制属性是否可见
/// </summary>
/// <param name="obj"></param>
/// <param name="propertyName"></param>
/// <param name="visible"></param>
public void SetPropertyVisibility(object obj,string propertyName,bool visible)
public static void SetPropertyVisibility(object obj,string propertyName,bool visible)
{
//Type type = typeof(BrowsableAttribute);
//PropertyDescriptorCollection props = TypeDescriptor.GetProperties(obj);
//AttributeCollection attrs = props[propertyName].Attributes;
//type.GetProperty("Browsable").SetValue(attrs[type], visible);

//AttributeCollection attributes =
// TypeDescriptor.GetProperties(obj)[propertyName].Attributes;
//// Checks to see if the property is browsable.
//BrowsableAttribute myAttribute = (BrowsableAttribute)attributes[typeof(
//BrowsableAttribute)];

//if (myAttribute.Browsable)
//{
// // Insert code here.
//}

//PropertyDescriptorCollection appSetingAttributes = TypeDescriptor.GetProperties(obj);
//Type type = typeof(BrowsableAttribute);
//FieldInfo fieldInfo = type.GetField("_displayName", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.CreateInstance);
//fieldInfo.SetValue(appSetingAttributes["TextID"].Attributes[displayType], "修改后的文本ID");
Type type = typeof(BrowsableAttribute);
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(obj);
AttributeCollection attrs = props[propertyName].Attributes;
FieldInfo fld = CallPrivatevariables(type,"<Browsable>k__BackingField");
// FieldInfo fld = type.GetField("Browsable",BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreReturn | BindingFlags.GetProperty);
fld.SetValue(attrs[type],visible);
}

/// <summary>
/// 获取指定对象的指定成员变量
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="obj"></param>
/// <param name="name"></param>
/// <returns></returns>
public static FieldInfo CallPrivatevariables(Type type,string name)
{
//BindingFlags flag = System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.NonPublic;
//Type type = obj.GetType();
//var fieldInfos_ = type.GetField(name, flag);
var fieldInfos = (System.Reflection.FieldInfo[])((System.Reflection.TypeInfo)type).DeclaredFields;
FieldInfo fieldInfo_ = null;
foreach (FieldInfo fieldInfo in fieldInfos)
{
if (fieldInfo.Name == name)
{
return fieldInfo;// (T)fieldInfo.GetValue(obj);
}
}
//FieldInfo fieldInfo = type.GetField(name, flag);
return fieldInfo_;// (T)fieldInfo_.GetValue(obj);
}
/// <summary>
/// 设置Category特性的值
@@ -477,7 +484,7 @@ namespace BeDesignerSCADA.ViewModel
private string _文本1;
private object _变量;

[Category("基本属性"), Description("Name"), Browsable(true), PropertyOrder(1)]
[Category("基本属性"), Description("Name"), Browsable(false), PropertyOrder(1)]
public string 名称
{
get


+ 23
- 0
SmartClient.sln Wyświetl plik

@@ -176,6 +176,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "6.配置工具", "6.配置
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeDesignerSCADA", "BeDesignerSCADA\BeDesignerSCADA.csproj", "{DF8B4C38-39DE-4220-AB60-885CAE6D1E47}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPASmart.RecipeManagement", "BPASmart.RecipeManagement\BPASmart.RecipeManagement.csproj", "{28EBFC11-184A-4B88-A7B3-84F3FD768520}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -1590,6 +1592,26 @@ Global
{DF8B4C38-39DE-4220-AB60-885CAE6D1E47}.Release|x64.Build.0 = Release|Any CPU
{DF8B4C38-39DE-4220-AB60-885CAE6D1E47}.Release|x86.ActiveCfg = Release|Any CPU
{DF8B4C38-39DE-4220-AB60-885CAE6D1E47}.Release|x86.Build.0 = Release|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Debug|ARM.ActiveCfg = Debug|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Debug|ARM.Build.0 = Debug|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Debug|ARM64.Build.0 = Debug|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Debug|x64.ActiveCfg = Debug|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Debug|x64.Build.0 = Debug|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Debug|x86.ActiveCfg = Debug|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Debug|x86.Build.0 = Debug|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Release|Any CPU.Build.0 = Release|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Release|ARM.ActiveCfg = Release|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Release|ARM.Build.0 = Release|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Release|ARM64.ActiveCfg = Release|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Release|ARM64.Build.0 = Release|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Release|x64.ActiveCfg = Release|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Release|x64.Build.0 = Release|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Release|x86.ActiveCfg = Release|Any CPU
{28EBFC11-184A-4B88-A7B3-84F3FD768520}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -1671,6 +1693,7 @@ Global
{AE49009F-B7D9-482E-AD1F-4514435272E1} = {1DA0F827-5F3D-4B87-9B51-6C0BF5365A3F}
{06F0B369-0483-46DD-82D2-70431FB505C1} = {7B0175AD-BB74-4A98-B9A7-1E289032485E}
{DF8B4C38-39DE-4220-AB60-885CAE6D1E47} = {06F0B369-0483-46DD-82D2-70431FB505C1}
{28EBFC11-184A-4B88-A7B3-84F3FD768520} = {CDC1E762-5E1D-4AE1-9DF2-B85761539086}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9AEC9B81-0222-4DE9-B642-D915C29222AC}


Ładowanie…
Anuluj
Zapisz