瀏覽代碼

Dosing权限管理

样式分支
NXX 2 年之前
父節點
當前提交
0f50f5c341
共有 25 個檔案被更改,包括 1040 行新增83 行删除
  1. +1
    -1
      BPASmartClient.Business/Plugin/MQTTMgr.cs
  2. +6
    -0
      BPASmartClient.CustomResource/Pages/Model/Global.cs
  3. +15
    -0
      BPASmartClient.CustomResource/Pages/Model/LocaMaterial.cs
  4. +17
    -0
      BPASmartClient.CustomResource/Pages/Model/MaterailConfig.cs
  5. +14
    -0
      BPASmartClient.CustomResource/Pages/Model/UserInfo.cs
  6. +400
    -19
      BPASmartClient.CustomResource/Pages/View/UserConfigView.xaml
  7. +3
    -6
      BPASmartClient.CustomResource/Pages/ViewModel/LoginViewModel.cs
  8. +7
    -0
      BPASmartClient.CustomResource/Pages/ViewModel/MainViewModel.cs
  9. +191
    -19
      BPASmartClient.CustomResource/Pages/ViewModel/UserConfigViewModel.cs
  10. +13
    -0
      BPASmartClient.MQTT/MQTTProxy.cs
  11. +2
    -1
      BPASmartClient.Model/柔性味魔方/RawMaterialModel.cs
  12. +4
    -4
      BPASmartClient/App.config
  13. +1
    -0
      DosingSystem/App.xaml.cs
  14. +15
    -5
      DosingSystem/Model/DeviceInquire.cs
  15. +15
    -0
      DosingSystem/Model/GlobalData.cs
  16. +3
    -0
      DosingSystem/Model/LocaPar.cs
  17. +1
    -1
      DosingSystem/Model/RecipeModel.cs
  18. +156
    -0
      DosingSystem/View/NewMaterialView.xaml
  19. +35
    -0
      DosingSystem/View/NewMaterialView.xaml.cs
  20. +11
    -0
      DosingSystem/View/RecipeSettingsView.xaml
  21. +3
    -3
      DosingSystem/ViewModel/ChangeDeviceNameViewModel.cs
  22. +64
    -0
      DosingSystem/ViewModel/NewMaterialViewModel.cs
  23. +52
    -24
      DosingSystem/ViewModel/NewRecipeViewModel.cs
  24. +10
    -0
      DosingSystem/ViewModel/RecipeSettingsViewModel.cs
  25. +1
    -0
      SmartClient.sln

+ 1
- 1
BPASmartClient.Business/Plugin/MQTTMgr.cs 查看文件

@@ -60,7 +60,7 @@ namespace BPASmartClient.Business
var MqttServerConfig = Plugin.GetInstance().GetPlugin<ConfigMgr>().MQTT_Config;
var MqttServerAccount = Plugin.GetInstance().GetPlugin<ConfigMgr>().Mqtt_Account;
//MQTT 初始化
mqttProxy.Connect(MqttServerAccount.UserName, MqttServerAccount.Password, MqttServerConfig.Host, MqttServerConfig.Port, Guid.NewGuid().ToString());
mqttProxy.Connect(MqttServerAccount.UserName, MqttServerAccount.Password, MqttServerConfig.Host, MqttServerConfig.Port, "qsqd--morks--"+ Guid.NewGuid().ToString());

ThreadManage.GetInstance().Start(() =>
{


+ 6
- 0
BPASmartClient.CustomResource/Pages/Model/Global.cs 查看文件

@@ -1,6 +1,8 @@
using BPASmartClient.CustomResource.Pages.Enums;
using BPASmartClient.Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -13,6 +15,10 @@ namespace BPASmartClient.CustomResource.Pages.Model

public static UserInfo userInfo { get; set; } = new UserInfo();
/// <summary>
/// 设备原料集合
/// </summary>
public static ObservableCollection<RawMaterialModel> DeviceRawMaterials { get; set; } = new ObservableCollection<RawMaterialModel>();
/// <summary>
/// 重置密码页面传值
/// </summary>
public static UserInfo changeUserInfo { get; set; } = null;


+ 15
- 0
BPASmartClient.CustomResource/Pages/Model/LocaMaterial.cs 查看文件

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

namespace BPASmartClient.CustomResource.Pages.Model
{
public class LocaMaterial
{
public ObservableCollection<RawMaterialModel> LocalMaterails { get; set; } = new ObservableCollection<RawMaterialModel>();
}
}

+ 17
- 0
BPASmartClient.CustomResource/Pages/Model/MaterailConfig.cs 查看文件

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

namespace BPASmartClient.CustomResource.Pages.Model
{
public class MaterailConfig
{
public string MaterialName { get; set; }

public string MaterialId { get; set; }

public string DeviceAddress { get; set; }
}
}

+ 14
- 0
BPASmartClient.CustomResource/Pages/Model/UserInfo.cs 查看文件

@@ -1,4 +1,5 @@
using BPASmartClient.CustomResource.Pages.Enums;
using BPASmartClient.Model;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
@@ -11,16 +12,29 @@ namespace BPASmartClient.CustomResource.Pages.Model
public class UserInfo:ObservableObject
{
public String LastLogInTime { get; set; } = "无";

public List<UserTreeViewModel> userTreeViewModels { get; set; }

public string Id { get { return _id; }set { _id = value;OnPropertyChanged(); } }
private string _id;

public Permission permission { get { return _perimission; } set { _perimission = value;OnPropertyChanged(); } }
private Permission _perimission;

public string UserName { get { return _userName; } set { _userName = value;OnPropertyChanged(); } }
private string _userName;

public string Password { get { return _password; } set { _password = value;OnPropertyChanged(); } }
private string _password;

public List<string> CardId { get; set; } = new List<string>();

public List<RawMaterialModel> locaRawMaterials { get; set; } = new List<RawMaterialModel>();

public List<RawMaterialModel> devRawMaterials { get; set; } = new List<RawMaterialModel>();




}
}

+ 400
- 19
BPASmartClient.CustomResource/Pages/View/UserConfigView.xaml 查看文件

@@ -224,6 +224,131 @@
</Setter>
</Style>

<!--切换button-->
<Style x:Key="changebutton_local" TargetType="Button">
<Setter Property="Height" Value="32"/>
<Setter Property="Width" Value="130"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button" >
<Border x:Name="border" BorderThickness="0" BorderBrush="White" SnapsToDevicePixels="True">
<Border.Background>
<DrawingBrush>
<DrawingBrush.Drawing>
<GeometryDrawing Brush="#009DFF">
<GeometryDrawing.Pen>
<Pen x:Name="pen" Thickness="3" Brush="{TemplateBinding BorderBrush }" ></Pen>
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry >
<PathGeometry Figures="m-70 -80 L200 -80 L200 80 L70 80 L-70 80 A 10,10 0 0 1 -80,70 L-80 70 L-80 -70 A 10,10 0 0 1 -70,-80"></PathGeometry>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</Border.Background>
<TextBlock Text="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="0,5,0,0" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
</Trigger>
<DataTrigger Binding="{Binding IsChecked}" Value="true">
<Setter Property="Height" Value="43"/>
<Setter Property="Width" Value="133"/>
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect Color="Black" Direction="220" ShadowDepth="15" Opacity="1"/>
</Setter.Value>
</Setter>
<Setter TargetName="border" Property="Background" >
<Setter.Value>
<DrawingBrush>
<DrawingBrush.Drawing>
<GeometryDrawing Brush="#009DFF">
<GeometryDrawing.Pen>
<Pen Thickness="5" Brush="White" ></Pen>
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry >
<PathGeometry Figures="m-70 -80 L200 -80 L200 80 L200 80 L50 80 L60 130 L70 80 L-70 80 A 10,10 0 0 1 -80,70 L-80 70 L-80 -70 A 10,10 0 0 1 -70,-80"></PathGeometry>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</Setter.Value>
</Setter>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>

</Style.Triggers>
</Style>

<Style x:Key="changebutton_device" TargetType="Button">
<Setter Property="Height" Value="32"/>
<Setter Property="Width" Value="130"/>
<Setter Property="FontSize" Value="18"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button" >
<Border x:Name="border" BorderThickness="0" BorderBrush="White" SnapsToDevicePixels="True">
<Border.Background>
<DrawingBrush>
<DrawingBrush.Drawing>
<GeometryDrawing Brush="#009DFF">
<GeometryDrawing.Pen>
<Pen x:Name="pen" Thickness="3" Brush="{TemplateBinding BorderBrush }" ></Pen>
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry >
<PathGeometry Figures="m-70 -80 L200 -80 L200 80 L70 80 L-70 80 A 10,10 0 0 1 -80,70 L-80 70 L-80 -70 A 10,10 0 0 1 -70,-80"></PathGeometry>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</Border.Background>
<TextBlock Text="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="0,5,0,0" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
</Trigger>
<DataTrigger Binding="{Binding IsChecked}" Value="false">
<Setter Property="Height" Value="43"/>
<Setter Property="Width" Value="133"/>
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect Color="Black" Direction="220" ShadowDepth="15" Opacity="1"/>
</Setter.Value>
</Setter>
<Setter TargetName="border" Property="Background" >
<Setter.Value>
<DrawingBrush>
<DrawingBrush.Drawing>
<GeometryDrawing Brush="#009DFF">
<GeometryDrawing.Pen>
<Pen Thickness="5" Brush="White" ></Pen>
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry >
<PathGeometry Figures="m-70 -80 L200 -80 L200 80 L200 80 L50 80 L60 130 L70 80 L-70 80 A 10,10 0 0 1 -80,70 L-80 70 L-80 -70 A 10,10 0 0 1 -70,-80"></PathGeometry>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</Setter.Value>
</Setter>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>

</Style>



@@ -243,13 +368,13 @@
<Image Source="../../Image/权限背景.png" Stretch="Fill"/>
<Grid Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="80"/>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
<RowDefinition Height="60"/>
<RowDefinition Height="40"/>
<RowDefinition Height="10*"/>
<RowDefinition Height="40"/>
<RowDefinition Height="13*"/>
<RowDefinition Height="50"/>
<RowDefinition Height="10"/>
<RowDefinition Height="5"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="{Binding UserName}" HorizontalAlignment="Center"
@@ -262,7 +387,7 @@
</StackPanel>
<TextBlock Grid.Row="1"
Text="页面权限分配" Margin="10,0,0,0"
HorizontalAlignment="Center" VerticalAlignment="Center"
HorizontalAlignment="Center" VerticalAlignment="Top"
FontSize="20"
Foreground="#ddd"/>
<TextBlock Grid.Row="3"
@@ -281,23 +406,25 @@
</Grid.ColumnDefinitions>
<TextBlock Text="权限列表" Width="20"
TextWrapping="Wrap" Grid.Column="0"
HorizontalAlignment="Right" VerticalAlignment="Center"
HorizontalAlignment="Center" VerticalAlignment="Center"
FontSize="20"
Foreground="#ddd"/>
<TextBlock Text="当前用户权限" Width="20"
Grid.Column="4"
TextWrapping="Wrap"
HorizontalAlignment="Left" VerticalAlignment="Center"
HorizontalAlignment="Center" VerticalAlignment="Center"
FontSize="20"
Foreground="#ddd"/>
<!--#region 页面权限-->
<ScrollViewer Grid.Column="1" Margin="20,0,0,0" Template="{StaticResource ScrollViewerControlTemplate1}" CanContentScroll="True">
<Border Grid.Column="1" BorderBrush="#1874CD" BorderThickness="1" />
<Border Grid.Column="3" BorderBrush="#1874CD" BorderThickness="1" />
<ScrollViewer Grid.Column="1" Margin="20,5,5,5" Template="{StaticResource ScrollViewerControlTemplate1}" CanContentScroll="True" >
<TreeView x:Name="MyTreeView" ItemsSource="{Binding pageTreeViewModels}"
ScrollViewer.VerticalScrollBarVisibility="Disabled" HorizontalAlignment="Stretch" Background="Transparent" BorderBrush="Transparent"></TreeView>
</ScrollViewer>


<ScrollViewer Grid.Column="3" Margin="10,0,20,0" Template="{StaticResource ScrollViewerControlTemplate1}" CanContentScroll="True">
<ScrollViewer Grid.Column="3" Margin="10,0,10,0" Template="{StaticResource ScrollViewerControlTemplate1}" CanContentScroll="True">
<ListBox x:Name="RightListBox" Grid.Column="3" Background="Transparent" ItemContainerStyle="{StaticResource ItemContainer}" FocusVisualStyle="{x:Null}"
ItemsSource="{Binding SelectePage}" >
<ListBox.Template>
@@ -343,18 +470,18 @@
<StackPanel Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Foreground="White" Background="#009DFF"
FontSize="16" Height="50" Width="70" Margin="10,20"
Command="{Binding AddAllPageCommand}">
Command="{Binding AddAllCommand}" CommandParameter="page">
<TextBlock Text="全部
添加" TextWrapping="Wrap"/>
</Button>
<Button Foreground="White" Background="#009DFF"
FontSize="16" Height="50" Width="70" Margin="10,20"
Command="{Binding DeleteAllPageCommand}">
Command="{Binding DeleteAllCommand}" CommandParameter="page">
<TextBlock Text="全部
移除" TextWrapping="Wrap"/>
</Button>
</StackPanel>
<!--#endregion-->
</Grid>

@@ -366,17 +493,271 @@
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="50"/>
</Grid.ColumnDefinitions>
<TextBlock Text="当前用户权限" Width="20"
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="权限列表" Width="20"
Grid.Row="1"
TextWrapping="Wrap"
HorizontalAlignment="Center" VerticalAlignment="Center"
FontSize="20"
Foreground="#ddd"/>
<TextBlock Text="权限列表" Width="20"
<TextBlock Text="当前用户权限" Width="20"
Grid.Row="1"
Grid.Column="4"
TextWrapping="Wrap"
HorizontalAlignment="Center" VerticalAlignment="Center"
FontSize="20"
Foreground="#ddd"/>

<Button Content="本地原料" Grid.Column="1" Style="{DynamicResource changebutton_local}" HorizontalAlignment="Right"
Command="{Binding ChangeMaterailPageCommand}" CommandParameter="Local"/>
<Button Content="设备原料" Grid.Column="3" Style="{DynamicResource changebutton_device}" HorizontalAlignment="Left"
Command="{Binding ChangeMaterailPageCommand}" CommandParameter="Device"/>
<!--#region 本地原料权限-->
<Border Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" BorderBrush="#1874CD" BorderThickness="1"
Visibility="{Binding VisibilityLocal}">
<Grid Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" BorderBrush="#1874CD" BorderThickness="1" />
<Border Grid.Column="2" BorderBrush="#1874CD" BorderThickness="1" />
<ScrollViewer Width="230" Margin="20,5,5,5" Template="{StaticResource ScrollViewerControlTemplate1}" CanContentScroll="True" HorizontalAlignment="Right" >
<ListBox Background="Transparent" ItemContainerStyle="{StaticResource ItemContainer}" FocusVisualStyle="{x:Null}"
ItemsSource="{Binding LoaclMaterails}" >
<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 RawMaterialName}" Foreground="White" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Left" />
<Button x:Name="BtnDelete" Grid.Column="1" Background="Transparent" ToolTip="移除" VerticalAlignment="Center" HorizontalAlignment="Left"
Command="{Binding DataContext.AddLoaclMaterialCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"
CommandParameter="{Binding Path=Text,ElementName=tb_Name}">
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid>
<Rectangle x:Name="BtnRetangle" Height="17" Width="17" 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="19"></Setter>
<Setter TargetName="BtnRetangle" Property="Width" Value="19"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>


<ScrollViewer Grid.Column="2" Margin="10,0,10,0" Template="{StaticResource ScrollViewerControlTemplate1}" CanContentScroll="True">
<ListBox Background="Transparent" ItemContainerStyle="{StaticResource ItemContainer}" FocusVisualStyle="{x:Null}"
Width="230"
ItemsSource="{Binding UserLoaclMaterails}" >
<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 RawMaterialName}" Foreground="White" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Left" />
<Button x:Name="BtnDelete" Grid.Column="1" Background="Transparent" ToolTip="移除" VerticalAlignment="Center" HorizontalAlignment="Left"
Command="{Binding DataContext.DeleteLoaclMaterialCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"
CommandParameter="{Binding Path=Text,ElementName=tb_Name}">
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid>
<Rectangle x:Name="BtnRetangle" Height="17" Width="17" 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="19"></Setter>
<Setter TargetName="BtnRetangle" Property="Width" Value="19"></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="16" Height="50" Width="70" Margin="10,20"
Command="{Binding AddAllCommand}" CommandParameter="local">
<TextBlock Text="全部
添加" TextWrapping="Wrap"/>
</Button>
<Button Foreground="White" Background="#009DFF"
FontSize="16" Height="50" Width="70" Margin="10,20"
Command="{Binding DeleteAllCommand}" CommandParameter="local">
<TextBlock Text="全部
移除" TextWrapping="Wrap"/>
</Button>
</StackPanel>


</Grid>
</Border>
<!--#endregion-->
<!--#region 设备原料权限-->
<Border Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" BorderBrush="#1874CD" BorderThickness="1"
Visibility="{Binding VisibilityDevice}">
<Grid Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<Border Grid.Column="0" BorderBrush="#1874CD" BorderThickness="1" />
<Border Grid.Column="2" BorderBrush="#1874CD" BorderThickness="1" />
<ScrollViewer Width="230" Margin="20,5,5,5" Template="{StaticResource ScrollViewerControlTemplate1}" CanContentScroll="True" HorizontalAlignment="Right" >
<ListBox Background="Transparent" ItemContainerStyle="{StaticResource ItemContainer}" FocusVisualStyle="{x:Null}"
ItemsSource="{Binding DeviceMaterails}" >
<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 RawMaterialName}" Foreground="White" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Left" />
<Button x:Name="BtnDelete" Grid.Column="1" Background="Transparent" ToolTip="移除" VerticalAlignment="Center" HorizontalAlignment="Left"
Command="{Binding DataContext.AddDeviceMaterialCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"
CommandParameter="{Binding Path=Text,ElementName=tb_Name}">
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid>
<Rectangle x:Name="BtnRetangle" Height="17" Width="17" 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="19"></Setter>
<Setter TargetName="BtnRetangle" Property="Width" Value="19"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>


<ScrollViewer Grid.Column="2" Margin="10,0,10,0" Template="{StaticResource ScrollViewerControlTemplate1}" CanContentScroll="True">
<ListBox Background="Transparent" ItemContainerStyle="{StaticResource ItemContainer}" FocusVisualStyle="{x:Null}"
Width="230"
ItemsSource="{Binding UserDeviceMaterails}" >
<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 RawMaterialName}" Foreground="White" FontSize="15" VerticalAlignment="Center" HorizontalAlignment="Left" />
<Button x:Name="BtnDelete" Grid.Column="1" Background="Transparent" ToolTip="移除" VerticalAlignment="Center" HorizontalAlignment="Left"
Command="{Binding DataContext.DeleteDeviceMaterialCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBox}}"
CommandParameter="{Binding Path=Text,ElementName=tb_Name}">
<Button.Template>
<ControlTemplate TargetType="Button">
<Grid>
<Rectangle x:Name="BtnRetangle" Height="17" Width="17" 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="19"></Setter>
<Setter TargetName="BtnRetangle" Property="Width" Value="19"></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="16" Height="50" Width="70" Margin="10,20"
Command="{Binding AddAllCommand}" CommandParameter="device">
<TextBlock Text="全部
添加" TextWrapping="Wrap"/>
</Button>
<Button Foreground="White" Background="#009DFF"
FontSize="16" Height="50" Width="70" Margin="10,20"
Command="{Binding DeleteAllCommand}" CommandParameter="device">
<TextBlock Text="全部
移除" TextWrapping="Wrap"/>
</Button>
</StackPanel>



</Grid>
</Border>
<!--#endregion-->
</Grid>
<Grid Grid.Row="5">
<Grid.ColumnDefinitions>
@@ -385,14 +766,14 @@
</Grid.ColumnDefinitions>
<Button Content="保存"
Background="#009DFF"
Margin="200,5,20,5"
Margin="200,10,20,0"
BorderThickness="0"
Command="{Binding SaveCommand}"
FontSize="20"
Foreground="White"
TabIndex="3" />
<Button Content="取消" Grid.Column="1" Background="#009DFF"
Margin="20,5,200,5"
Margin="20,10,200,0"
BorderThickness="0"
Command="{Binding CancelCommand}"
FontSize="20"
@@ -400,7 +781,7 @@
TabIndex="3"/>
</Grid>
</Grid>
</Grid>
</Border>
</Window>

+ 3
- 6
BPASmartClient.CustomResource/Pages/ViewModel/LoginViewModel.cs 查看文件

@@ -29,9 +29,7 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel
var res = Global.userManager.userInfos.FirstOrDefault(p => p.CardId?.FirstOrDefault(s => s == cardId && s.Length > 0) != null);
if (res != null)
{
Global.userInfo.permission = res.permission;
Global.userInfo.UserName = res.UserName;
Global.userInfo.Password = res.Password;
Global.userInfo = res;
for (int i = 0; i < MenuManage.GetInstance.menuModels.Count; i++)
{
if (MenuManage.GetInstance.menuModels.ElementAt(i).MainMenuPermission.Contains(res.permission))
@@ -60,9 +58,8 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel
var res = Global.userManager.userInfos.FirstOrDefault(p => p.UserName == UserName && p.Password == Password);
if (res != null)
{
Global.userInfo.permission = res.permission;
Global.userInfo.UserName = res.UserName;
Global.userInfo.Password = res.Password;
Global.userInfo = res;
Global.userInfo.LastLogInTime = DateTime.Now.ToString();
res.LastLogInTime = DateTime.Now.ToString();
Config.GetInstance.SaveUser();


+ 7
- 0
BPASmartClient.CustomResource/Pages/ViewModel/MainViewModel.cs 查看文件

@@ -8,6 +8,7 @@ using System.Threading.Tasks;
using System.Windows;
using BPASmartClient.CustomResource.Pages.Model;
using BPASmartClient.Helper;
using BPASmartClient.Model;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;

@@ -25,6 +26,12 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel
PermissionChange();
}), "PermissionChange");

//测试用
Global.DeviceRawMaterials.Add(new RawMaterialModel { RawMaterialName = "营养强化剂", DeviceIp = "192.168.1.111" });
Global.DeviceRawMaterials.Add(new RawMaterialModel { RawMaterialName = "甜味剂", DeviceIp = "192.168.1.112" });
Global.DeviceRawMaterials.Add(new RawMaterialModel { RawMaterialName = "抗氧化剂", DeviceIp = "192.168.1.113" });
Global.DeviceRawMaterials.Add(new RawMaterialModel { RawMaterialName = "食用香料", DeviceIp = "192.168.1.114" });

}

private void PermissionChange()


+ 191
- 19
BPASmartClient.CustomResource/Pages/ViewModel/UserConfigViewModel.cs 查看文件

@@ -1,6 +1,7 @@
using BPASmartClient.CustomResource.Pages.Model;
using BPASmartClient.CustomResource.Pages.View;
using BPASmartClient.Helper;
using BPASmartClient.Model;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using System;
@@ -9,6 +10,7 @@ using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace BPASmartClient.CustomResource.Pages.ViewModel
{
@@ -22,27 +24,68 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel
/// 已选择页面
/// </summary>
public ObservableCollection<UserTreeViewModel> SelectePage { get; set; } = new ObservableCollection<UserTreeViewModel>();
/// <summary>
/// 本地原料集合
/// </summary>
public ObservableCollection<RawMaterialModel> LoaclMaterails { get; set; } = Json<LocaMaterial>.Data.LocalMaterails;
/// <summary>
/// 设备原料集合
/// </summary>
public ObservableCollection<RawMaterialModel> DeviceMaterails { get; set; } = Global.DeviceRawMaterials;
/// <summary>
/// 用户本地原料权限
/// </summary>
public ObservableCollection<RawMaterialModel> UserLoaclMaterails { get; set; } = new ObservableCollection<RawMaterialModel>();
/// <summary>
/// 用户设备原料权限
/// </summary>
public ObservableCollection<RawMaterialModel> UserDeviceMaterails { get; set; } = new ObservableCollection<RawMaterialModel>();

/// <summary>
/// 切换本地和设备原料权限
/// </summary>
public bool IsChecked { get { return _isChecked; } set { _isChecked = value;OnPropertyChanged(); } }
private bool _isChecked = true;

/// <summary>
/// 用户名
/// </summary>
public string UserName { get { return _username; } set { _username = value; OnPropertyChanged(); } }
private string _username;
/// <summary>
/// 本地原料权限显示
/// </summary>
public Visibility VisibilityLocal { get { return _visibilityLocal; } set { _visibilityLocal = value; OnPropertyChanged(); } }
private Visibility _visibilityLocal = Visibility.Visible;
/// <summary>
/// 设备原料权限显示
/// </summary>
public Visibility VisibilityDevice { get { return _visibilityDevice; } set { _visibilityDevice = value; OnPropertyChanged(); } }
private Visibility _visibilityDevice = Visibility.Collapsed;

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

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

public RelayCommand DeleteAllPageCommand { get; set; }

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

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

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

public RelayCommand SaveCommand { get; set; }

public RelayCommand CancelCommand { get; set; }

public RelayCommand<object> AddLoaclMaterialCommand { get; set; }
public RelayCommand<object> DeleteLoaclMaterialCommand { get; set; }
public RelayCommand<object> AddDeviceMaterialCommand { get; set; }
public RelayCommand<object> DeleteDeviceMaterialCommand { get; set; }


private void AddUserPage(object o)
{
if (o == null) return;
@@ -63,6 +106,7 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel
}
}
}

private void DeleteUserPage(object o)
{
if (o == null) return;
@@ -73,41 +117,140 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel
}
}

private void ChangeMaterailPage(object o)
{

public UserConfigViewModel()
if (o == null) return;
if (o is string type)
{
if(type == "Local") {IsChecked = true;VisibilityLocal = Visibility.Visible; VisibilityDevice = Visibility.Collapsed; }
else {IsChecked = false; VisibilityDevice = Visibility.Visible;VisibilityLocal = Visibility.Collapsed; }

}
}

private void AddLoaclMaterial(object o)
{
AddUserPageCommand = new RelayCommand<object>(AddUserPage);

DeleteUserPageCommand = new RelayCommand<object>(DeleteUserPage);
if (o == null) return;
if (o is string materail)
{
var res = LoaclMaterails.FirstOrDefault(p=>p.RawMaterialName == materail);
if(UserLoaclMaterails.FirstOrDefault(p=>p.RawMaterialName == materail)==null) UserLoaclMaterails.Add(res);
}
}

DeleteAllPageCommand = new RelayCommand(() =>
private void DeleteLoaclMaterial(object o)
{
if (o == null) return;
if (o is string materail)
{
SelectePage.Clear();
});
var res = UserLoaclMaterails.FirstOrDefault(p => p.RawMaterialName == materail);
UserLoaclMaterails.Remove(res);
}
}

AddAllPageCommand = new RelayCommand(() =>
private void AddDeviceMaterial(object o)
{
if (o == null) return;
if (o is string materail)
{
foreach(UserTreeViewModel item in pageTreeViewModels)
var res = DeviceMaterails.FirstOrDefault(p => p.RawMaterialName == materail);
if(UserDeviceMaterails.FirstOrDefault(p=>p.DeviceIp == res.DeviceIp) == null)
{
foreach(var res in item.TreeViewItems)
UserDeviceMaterails.Add(res);
}
}
}

private void DeleteDeviceMaterial(object o)
{
if (o == null) return;
if (o is string materail)
{
var res = UserDeviceMaterails.FirstOrDefault(p => p.RawMaterialName == materail);
UserDeviceMaterails.Remove(res);
}
}

private void AddAll(object o)
{
if (o == null) return;
if (o.ToString() == "page")
{
SelectePage.Clear();
foreach (UserTreeViewModel item in pageTreeViewModels)
{
foreach (var res in item.TreeViewItems)
{
if (!SelectePage.Contains(res)) SelectePage.Add(res);
SelectePage.Add(res);
}
}
});

}
else if (o.ToString() == "local")
{
UserLoaclMaterails.Clear();
foreach (RawMaterialModel item in LoaclMaterails)
{
UserLoaclMaterails.Add(item);
}
}
else if (o.ToString() == "device")
{
UserDeviceMaterails.Clear();
foreach (RawMaterialModel item in DeviceMaterails)
{
UserDeviceMaterails.Add(item);
}
}
}

private void DeleteAll(object o)
{
if (o == null) return;
if(o.ToString() == "page")
{
SelectePage.Clear();
}
else if(o.ToString() == "local")
{
UserLoaclMaterails.Clear();
}
else if(o.ToString() == "device")
{
UserDeviceMaterails.Clear();
}
}



public UserConfigViewModel()
{
AddUserPageCommand = new RelayCommand<object>(AddUserPage);

DeleteUserPageCommand = new RelayCommand<object>(DeleteUserPage);

DeleteAllCommand = new RelayCommand<object>(DeleteAll);


AddAllCommand = new RelayCommand<object>(AddAll);

ChangeMaterailPageCommand = new RelayCommand<object>(ChangeMaterailPage);

SaveCommand = new RelayCommand(() =>
{
var res = Global.userManager.userInfos.FirstOrDefault(p => p.UserName == Global.changeUserInfo.UserName && p.Password == Global.changeUserInfo.Password);
if(res != null)
{
res.userTreeViewModels = new List<UserTreeViewModel>();
res.userTreeViewModels.AddRange(SelectePage);
res.locaRawMaterials = new List<RawMaterialModel>();
res.locaRawMaterials.AddRange(UserLoaclMaterails);
res.devRawMaterials = new List<RawMaterialModel>();
res.devRawMaterials.AddRange(UserDeviceMaterails);
Config.GetInstance.SaveUser();
}
Global.changeUserInfo = null;
@@ -120,6 +263,15 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel
ActionManage.GetInstance.Send("UserConfigViewCancel");
});

AddLoaclMaterialCommand = new RelayCommand<object>(AddLoaclMaterial);

DeleteLoaclMaterialCommand = new RelayCommand<object>(DeleteLoaclMaterial);

AddDeviceMaterialCommand = new RelayCommand<object>(AddDeviceMaterial);

DeleteDeviceMaterialCommand = new RelayCommand<object>(DeleteDeviceMaterial);


foreach (var item in MenuManage.GetInstance.menuModels)
{
List<UserTreeViewModel> list = new List<UserTreeViewModel>();
@@ -133,7 +285,7 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel
TreeViewItems = list
});
}
//用户已拥有权限
if(Global.changeUserInfo != null)
{
UserName = Global.changeUserInfo.UserName;
@@ -146,12 +298,32 @@ namespace BPASmartClient.CustomResource.Pages.ViewModel
SelectePage.Add(item);
}
}
if(Global.changeUserInfo.locaRawMaterials.Count>0)
{
foreach(RawMaterialModel model in Global.changeUserInfo.locaRawMaterials)
{
UserLoaclMaterails.Add(model);
}
}

if (Global.changeUserInfo.devRawMaterials.Count > 0)
{
foreach (RawMaterialModel model in Global.changeUserInfo.devRawMaterials)
{
UserDeviceMaterails.Add(model);
}
}
}
}








}

}


+ 13
- 0
BPASmartClient.MQTT/MQTTProxy.cs 查看文件

@@ -31,6 +31,8 @@ namespace BPASmartClient.MQTT

public bool IsConnected { get; set; }

bool push = true;

Action UseDisconnectedAction;


@@ -152,8 +154,10 @@ namespace BPASmartClient.MQTT
/// <param name="content">需要发布的内容</param>
public async void Publish(string topic, string content)
{
;
if (client != null && client.IsConnected)
{
push = true;
var msg = new MqttApplicationMessageBuilder().WithTopic(topic).WithPayload(content).WithExactlyOnceQoS().Build();
try
{
@@ -161,6 +165,15 @@ namespace BPASmartClient.MQTT
}
catch { }
}
if(!client.IsConnected)
{
if(push)
{
MessageLog.GetInstance.ShowEx("MQTT未连接");
push = false;
}
}
}




DosingSystem/Model/RawMaterialModel.cs → BPASmartClient.Model/柔性味魔方/RawMaterialModel.cs 查看文件

@@ -5,7 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.DosingSystem.Model
namespace BPASmartClient.Model
{
/// <summary>
/// 原料模块
@@ -29,6 +29,7 @@ namespace BPASmartClient.DosingSystem.Model
public uint RawMaterialWeight { get { return _mRawMaterialWeight; } set { _mRawMaterialWeight = value; OnPropertyChanged(); } }
private uint _mRawMaterialWeight;


/// <summary>
/// 原料类型 MW18
/// 1:液体

+ 4
- 4
BPASmartClient/App.config 查看文件

@@ -7,9 +7,9 @@
<add key="IsEnableTest" value="false"/>

<!--测试环境-->
<add key="apollouri" value="http://10.2.1.21:28080/"/>
<!--<add key="apollouri" value="http://10.2.1.21:28080/"/>
<add key="AppId" value="test1_HostComputer"/>
<add key ="Namespaces" value="DEV.test1.Config"/>
<add key ="Namespaces" value="DEV.test1.Config"/>-->

<!--开发环境-->
<!--<add key="apollouri" value="http://10.2.1.21:28080/"/>
@@ -17,9 +17,9 @@
<add key ="Namespaces" value="DEV.Config"/>-->

<!--正式环境-->
<!--<add key="apollouri" value="http://47.108.65.220:28080/"/>
<add key="apollouri" value="http://47.108.65.220:28080/"/>
<add key="AppId" value="HostComputer"/>
<add key ="Namespaces" value="TEST1.Config"/>-->
<add key ="Namespaces" value="TEST1.Config"/>

<!--阿里云上报启动方式:API 或者 LOCAL-->
<!--API :通过客户端ID,调用接口查询“设备连接信息”-->


+ 1
- 0
DosingSystem/App.xaml.cs 查看文件

@@ -202,6 +202,7 @@ namespace BPASmartClient.DosingSystem
{
Config.GetInstance.Init();
Json<LocaPar>.Read();
Json<LocaMaterial>.Read();
}

}


+ 15
- 5
DosingSystem/Model/DeviceInquire.cs 查看文件

@@ -12,6 +12,7 @@ using System.Threading;
using System.Threading.Tasks;
using BPASmartClient.CustomResource.UserControls.MessageShow;
using BPASmartClient.CustomResource.Pages.Model;
using BPASmartClient.Model;

namespace BPASmartClient.DosingSystem.Model
{
@@ -110,9 +111,17 @@ namespace BPASmartClient.DosingSystem.Model
}
}
}

if (!NewRecipeViewModel.RawMaterialNames.Contains(DeviceName))
NewRecipeViewModel.RawMaterialNames.Add(DeviceName);
if(Global.DeviceRawMaterials.Count > 0)
{
if(Global.DeviceRawMaterials.FirstOrDefault(p=>p.RawMaterialName == DeviceName) == null)
{
Global.DeviceRawMaterials.Add(new RawMaterialModel() { RawMaterialName = DeviceName, DeviceIp = ip });
}
}
else
{
Global.DeviceRawMaterials.Add(new RawMaterialModel() { RawMaterialName = DeviceName, DeviceIp = ip });
}

}));
}
@@ -136,8 +145,9 @@ namespace BPASmartClient.DosingSystem.Model
App.Current.Dispatcher.Invoke(new Action(() =>
{
DeviceListViewModel.devices.Remove(res);
if (NewRecipeViewModel.RawMaterialNames.Contains(res.DeviceName))
NewRecipeViewModel.RawMaterialNames.Remove(res.DeviceName);
var item = Global.DeviceRawMaterials.FirstOrDefault(P => P.RawMaterialName == res.DeviceName);
if (item!=null) Global.DeviceRawMaterials.Remove(item);

}));
if (DeviceLists.ContainsKey(ip)) DeviceLists[ip].Dispose();
});


+ 15
- 0
DosingSystem/Model/GlobalData.cs 查看文件

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

namespace BPASmartClient.DosingSystem.Model
{
public class GlobalData
{
}
}

+ 3
- 0
DosingSystem/Model/LocaPar.cs 查看文件

@@ -5,11 +5,14 @@ using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using BPASmartClient.DosingSystem.ViewModel;
using BPASmartClient.Model;

namespace BPASmartClient.DosingSystem.Model
{
public class LocaPar
{
public ObservableCollection<RecipeModel> Recipes { get; set; } = new ObservableCollection<RecipeModel>();

}
}

+ 1
- 1
DosingSystem/Model/RecipeModel.cs 查看文件

@@ -5,7 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using BPASmartClient.DosingSystem.ViewModel;
using BPASmartClient.Model;
using Microsoft.Toolkit.Mvvm.ComponentModel;

namespace BPASmartClient.DosingSystem.Model


+ 156
- 0
DosingSystem/View/NewMaterialView.xaml 查看文件

@@ -0,0 +1,156 @@
<Window x:Class="BPASmartClient.DosingSystem.View.NewMaterialView"
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.DosingSystem.View"
xmlns:vm="clr-namespace:BPASmartClient.DosingSystem.ViewModel"
mc:Ignorable="d"
Title="NewMateritalView"
Width="600"
Height="600"
AllowsTransparency="True"
Background="{x:Null}"
Topmost="True"
WindowStartupLocation="CenterScreen"
WindowStyle="None">
<Window.DataContext>
<vm:NewMaterialViewModel/>
</Window.DataContext>
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/Themes/GenricStyle.xaml" />
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/Themes/MyStyle.xaml" />

<ResourceDictionary>
<!--#region ListBox样式-->
<Style x:Key="ListBoxItemStyle1" TargetType="{x:Type ListBoxItem}">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="BorderBrush" Value="{x:Null}" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontSize" Value="20" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="border" CornerRadius="8">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!--#endregion-->
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>

<Border Name="br" BorderThickness="1">
<Border.Background>
<ImageBrush ImageSource="/BPASmartClient.CustomResource;component/Image/bg.png" />
</Border.Background>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="5" />
<RowDefinition Height="*"/>
<RowDefinition Height="40"/>
<RowDefinition Height="5" />
<RowDefinition Height="5*" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock
Margin="10,0,0,0"
Background="Transparent"
FontSize="20"
Foreground="#FF2AB2E7"
Text="请输入原料名称:" />


<TextBox
Grid.Column="1"
Width="200"
Height="30"
Margin="10"
FontSize="16"
Text="{Binding MaterialName}" />

<Button
Width="80"
Height="30"
Margin="10"
Command="{Binding SaveCommand}"
Content="保存" Cursor="Hand" />
<Button
Name="btClose"
Width="80"
Height="30"
Margin="10"
Click="btClose_Click"
Content="取消" />

</StackPanel>
<TextBlock Grid.Row="2"
Margin="0,0,5,0"
HorizontalAlignment="Center"
Background="Transparent"
FontSize="16"
Foreground="Red"
Text="{Binding ErrorInfo}"></TextBlock>
<Grid Grid.Row="4">
<Grid.RowDefinitions>
<RowDefinition Height="40"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBlock Text="本地原料" HorizontalAlignment="Center" FontSize="25" Foreground="#FF2AB2E7"/>
<Border Grid.Row="1" BorderBrush="#FF2AB2E7" BorderThickness="1" Margin="100,10">
<ScrollViewer Grid.Row="1" BorderBrush="#FF2AB2E7" BorderThickness="1">
<ItemsControl ItemsSource="{Binding Materials}" Margin="10">
<ItemsControl.ItemTemplate>
<DataTemplate>
<RadioButton GroupName="all">
<RadioButton.Template>
<ControlTemplate TargetType="RadioButton">
<Grid Name="gr" Height="40">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock
Name="tb"
Grid.Column="0"
Width="150"
Height="29"
Margin="3,1"
VerticalAlignment="Center" HorizontalAlignment="Center"
FontSize="20"
Text="{Binding RawMaterialName}" />

<Button
Grid.Column="1"
Margin="10,0,10,0"
Command="{Binding DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}"
CommandParameter="{Binding RawMaterialId}"
Content="删除" />
</Grid>


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

</Grid>

</Border>
</Window>

+ 35
- 0
DosingSystem/View/NewMaterialView.xaml.cs 查看文件

@@ -0,0 +1,35 @@
using BPASmartClient.Helper;
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.DosingSystem.View
{
/// <summary>
/// NewMateritalView.xaml 的交互逻辑
/// </summary>
public partial class NewMaterialView : Window
{
public NewMaterialView()
{
InitializeComponent();
this.btClose.Click += (o, e) => { this.Close(); };
this.br.MouseLeftButtonDown += (o, e) => { if (e.LeftButton == MouseButtonState.Pressed) this.DragMove(); };
}

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

+ 11
- 0
DosingSystem/View/RecipeSettingsView.xaml 查看文件

@@ -52,6 +52,17 @@

<!--#region 操作按钮-->
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
<pry:IcoButton
Grid.Column="3"
Width="140"
Margin="10"
HorizontalAlignment="Left"
Command="{Binding NewMaterital}"
Content="新建原料"
FontSize="16"
Foreground="Aqua"
IcoText="&#xe626;"
Style="{StaticResource IcoButtonStyle}" />
<pry:IcoButton
Grid.Column="3"
Width="140"


+ 3
- 3
DosingSystem/ViewModel/ChangeDeviceNameViewModel.cs 查看文件

@@ -7,6 +7,7 @@ using BPASmartClient.Helper;
using BPASmartClient.DosingSystem.Model;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using BPASmartClient.CustomResource.Pages.Model;

namespace BPASmartClient.DosingSystem.ViewModel
{
@@ -34,10 +35,9 @@ namespace BPASmartClient.DosingSystem.ViewModel
ErrorInfo = "设备名称已存在";
else
{
NewRecipeViewModel.RawMaterialNames.Remove(DeviceListViewModel.devices.ElementAt(index).DeviceName);
NewRecipeViewModel.RawMaterialNames.Add(DeviceName);
var res = Global.DeviceRawMaterials.FirstOrDefault(p => p.RawMaterialName == DeviceListViewModel.devices.ElementAt(index).DeviceName);
res.RawMaterialName = DeviceName;
DeviceListViewModel.devices.ElementAt(index).DeviceName = DeviceName;

DeviceInquire.GetInstance.GetDevice(IpAddress).SetDeviceName(DeviceName);//设置PLC名称
for (int i = 0; i < Json<LocaPar>.Data.Recipes.Count; i++)
{


+ 64
- 0
DosingSystem/ViewModel/NewMaterialViewModel.cs 查看文件

@@ -0,0 +1,64 @@
using BPASmartClient.CustomResource.Pages.Model;
using BPASmartClient.DosingSystem.Model;
using BPASmartClient.Helper;
using BPASmartClient.Model;
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 BPASmartClient.DosingSystem.ViewModel;

public class NewMaterialViewModel:ObservableObject
{
public ObservableCollection<RawMaterialModel> Materials { get; set; } = Json<LocaMaterial>.Data.LocalMaterails;

public string MaterialName { get { return _materialName; } set { _materialName = value; OnPropertyChanged(); } }
private string _materialName = string.Empty;

public string ErrorInfo { get { return _mErrorInfo; } set { _mErrorInfo = value; OnPropertyChanged(); } }
private string _mErrorInfo;

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

public RelayCommand SaveCommand { get; set; }



private void Remove(object o)
{
if (o == null) return;
if(o is string id)
{
var res = Materials.FirstOrDefault(p=>p.RawMaterialId == id);
Materials.Remove(res);
Json<LocaMaterial>.Save();
MessageLog.GetInstance.ShowUserLog($"删除原料--{res.RawMaterialName}");
}
}

public NewMaterialViewModel()
{
RemoveCommand = new RelayCommand<object>(Remove);

SaveCommand = new RelayCommand(() =>
{
if(MaterialName == String.Empty) { ErrorInfo = "原料名称不能为空";return; }
if(Global.DeviceRawMaterials.FirstOrDefault(p=>p.RawMaterialName == MaterialName) != null) { ErrorInfo = "设备中已存在该原料名称";return;}
if(Json<LocaMaterial>.Data.LocalMaterails.FirstOrDefault(p=>p.RawMaterialName == MaterialName) != null) { ErrorInfo = "本地原料名称重复";return ;}
Json<LocaMaterial>.Data.LocalMaterails.Add(new RawMaterialModel { RawMaterialName = MaterialName, RawMaterialId = Guid.NewGuid().ToString() });
Json<LocaMaterial>.Save();
MessageLog.GetInstance.ShowUserLog($"添加原料--{MaterialName}");
});




}
}

+ 52
- 24
DosingSystem/ViewModel/NewRecipeViewModel.cs 查看文件

@@ -9,6 +9,7 @@ using Microsoft.Toolkit.Mvvm.Input;
using BPASmartClient.Helper;
using BPASmartClient.DosingSystem.Model;
using BPASmartClient.CustomResource.Pages.Model;
using BPASmartClient.Model;

namespace BPASmartClient.DosingSystem.ViewModel
{
@@ -54,6 +55,8 @@ namespace BPASmartClient.DosingSystem.ViewModel

SaveCommand = new RelayCommand(() =>
{
ErrorInfo = String.Empty;
if (RecipeName == String.Empty) { ErrorInfo = "配方名称未填写";return; }
for (int i = 0; i < RawMaterials.Count; i++)
{
var res = DeviceListViewModel.devices.FirstOrDefault(p => p.DeviceName == RawMaterials.ElementAt(i).RawMaterialName);
@@ -86,9 +89,53 @@ namespace BPASmartClient.DosingSystem.ViewModel
}
}
}

ActionManage.GetInstance.Send("CloseNewRecipeView");
});
ActionManage.GetInstance.Send("CloseNewRecipeView");
//RawMaterialNames.Add("乳化剂");
//RawMaterialNames.Add("酶制剂");
//RawMaterialNames.Add("增味剂");


//RawMaterialNames.Add("营养强化剂");
//RawMaterialNames.Add("抗结剂");
//RawMaterialNames.Add("消泡剂");
//RawMaterialNames.Add("膨松剂");
//RawMaterialNames.Add("防腐剂");
//RawMaterialNames.Add("着色剂");
//RawMaterialNames.Add("甜味剂");
//RawMaterialNames.Add("酸味剂");
//RawMaterialNames.Add("增白剂");
//RawMaterialNames.Add("香料");
//RawMaterialNames.Add("抗氧化剂");
//RawMaterialNames.Add("食用香料");
//RawMaterialNames.Add("增稠剂");

if (Global.userInfo.permission == CustomResource.Pages.Enums.Permission.管理员)
{
foreach (var item in Global.DeviceRawMaterials)
{
RawMaterialNames.Add(item.RawMaterialName);

}
foreach (var item in Json<LocaMaterial>.Data.LocalMaterails)
{
RawMaterialNames.Add(item.RawMaterialName);
}
}
else
{
foreach (var item in Global.DeviceRawMaterials)
{
if (Global.userInfo.devRawMaterials.FirstOrDefault(p => p.RawMaterialName == item.RawMaterialName) != null) RawMaterialNames.Add(item.RawMaterialName);

}
foreach (var item in Json<LocaMaterial>.Data.LocalMaterails)
{
if (Global.userInfo.locaRawMaterials.FirstOrDefault(p => p.RawMaterialName == item.RawMaterialName) != null) RawMaterialNames.Add(item.RawMaterialName);
}
}
}

private void AddRecipes()
@@ -106,31 +153,12 @@ namespace BPASmartClient.DosingSystem.ViewModel
});
}

static NewRecipeViewModel()
{
RawMaterialNames.Clear();
//RawMaterialNames.Add("乳化剂");
//RawMaterialNames.Add("酶制剂");
//RawMaterialNames.Add("增味剂");
RawMaterialNames.Add("营养强化剂");
//RawMaterialNames.Add("抗结剂");
//RawMaterialNames.Add("消泡剂");
//RawMaterialNames.Add("膨松剂");
//RawMaterialNames.Add("防腐剂");
//RawMaterialNames.Add("着色剂");
RawMaterialNames.Add("甜味剂");
//RawMaterialNames.Add("酸味剂");
//RawMaterialNames.Add("增白剂");
//RawMaterialNames.Add("香料");
RawMaterialNames.Add("抗氧化剂");
RawMaterialNames.Add("食用香料");
//RawMaterialNames.Add("增稠剂");
}

private string RecipCode = string.Empty;

public string RecipeName { get { return _mRecipeName; } set { _mRecipeName = value; OnPropertyChanged(); } }
private string _mRecipeName;
private string _mRecipeName = string.Empty;

public string ErrorInfo { get { return _mErrorInfo; } set { _mErrorInfo = value; OnPropertyChanged(); } }
private string _mErrorInfo;
@@ -143,6 +171,6 @@ namespace BPASmartClient.DosingSystem.ViewModel

public ObservableCollection<RawMaterialModel> RawMaterials { get; set; } = new ObservableCollection<RawMaterialModel>();

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

+ 10
- 0
DosingSystem/ViewModel/RecipeSettingsViewModel.cs 查看文件

@@ -17,6 +17,7 @@ using BPASmartClient.CustomResource.UserControls.Enum;
using System.Windows.Media;
using BPASmartClient.CustomResource.UserControls.MessageShow;
using BPASmartClient.CustomResource.Pages.Model;
using BPASmartClient.Model;

namespace BPASmartClient.DosingSystem.ViewModel
{
@@ -26,6 +27,12 @@ namespace BPASmartClient.DosingSystem.ViewModel
{
//Json<LocaPar>.Read();
Recipes = Json<LocaPar>.Data.Recipes;

NewMaterital = new RelayCommand(() =>
{
NewMaterialView newMateritalView = new NewMaterialView();
newMateritalView.ShowDialog();
});
NewRecipe = new RelayCommand(() =>
{
NewRecipeView nrv = new NewRecipeView();
@@ -60,8 +67,11 @@ namespace BPASmartClient.DosingSystem.ViewModel
MessageLog.GetInstance.ShowUserLog($"编辑配方名称——{res.RecipeName}");
}
});
}

public RelayCommand NewMaterital { get; set; }

public RelayCommand NewRecipe { get; set; }

public RelayCommand SaveRecipe { get; set; }


+ 1
- 0
SmartClient.sln 查看文件

@@ -1278,6 +1278,7 @@ Global
{BFA4E222-BBCC-4AC7-9EA4-4549AEF3174B} = {8712125E-14CD-4E1B-A1CE-4BDE03805942}
{75B55300-ABC3-4CA1-B9B6-DF954E6C7B44} = {8712125E-14CD-4E1B-A1CE-4BDE03805942}
{C0060FB3-7AEA-4D14-ADCE-DB78D3665D5B} = {666CB1A9-562E-453A-A2C7-FD9D77CFDFDD}
{1612F583-D328-45C6-8BB1-5D41B8F1D216} = {9FB27073-61A0-4FE3-94DB-5FDDE062332F}
{42D35B7C-764C-4692-AA85-9B343A0F5B7F} = {3D1D0E04-03FD-480A-8CF8-6E01A2E28625}
{B8D499BA-A18A-4FD6-B036-44F02B4D164B} = {3D1D0E04-03FD-480A-8CF8-6E01A2E28625}
EndGlobalSection


Loading…
取消
儲存