浏览代码

吉香居配料系统

样式分支
pry 2 年前
父节点
当前提交
b0d52bfa73
共有 18 个文件被更改,包括 512 次插入93 次删除
  1. +8
    -5
      BPASmartClient.CustomResource/Converters/StatusConverter.cs
  2. +1
    -1
      BPASmartClient.CustomResource/Themes/MyStyle.xaml
  3. +3
    -3
      BPASmartClient.Modbus/ModbusTcp.cs
  4. +1
    -0
      BPASmartClient.MorkS/ViewModel/DebugViewModel.cs
  5. +45
    -14
      DosingSystem/Model/DeviceInquire.cs
  6. +41
    -5
      DosingSystem/Model/RawMaterialModel.cs
  7. +122
    -0
      DosingSystem/View/ChangeDeviceNameView.xaml
  8. +31
    -0
      DosingSystem/View/ChangeDeviceNameView.xaml.cs
  9. +117
    -47
      DosingSystem/View/DeviceListView.xaml
  10. +18
    -10
      DosingSystem/View/NewRecipeView.xaml
  11. +1
    -0
      DosingSystem/View/NewRecipeView.xaml.cs
  12. +4
    -4
      DosingSystem/View/RecipeControlView.xaml
  13. +71
    -0
      DosingSystem/ViewModel/ChangeDeviceNameViewModel.cs
  14. +12
    -1
      DosingSystem/ViewModel/DeviceListViewModel.cs
  15. +1
    -0
      DosingSystem/ViewModel/MainViewModel.cs
  16. +8
    -1
      DosingSystem/ViewModel/NewRecipeViewModel.cs
  17. +27
    -1
      DosingSystem/ViewModel/RecipeControlViewModel.cs
  18. +1
    -1
      DosingSystem/ViewModel/RecipeSettingsViewModel.cs

+ 8
- 5
BPASmartClient.CustomResource/Converters/StatusConverter.cs 查看文件

@@ -13,22 +13,25 @@ namespace BPASmartClient.CustomResource.Converters
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
SolidColorBrush returnValue = new SolidColorBrush(Color.FromArgb(255, 0, 204, 255));
SolidColorBrush returnValue = Brushes.SandyBrown;
if (value != null && value is ushort statusValue)
{
switch (statusValue)
{
case 0:
returnValue = new SolidColorBrush(Color.FromArgb(255, 0, 204, 255));
returnValue = Brushes.SandyBrown;
break;
case 1:
returnValue = new SolidColorBrush(Color.FromArgb(255, 0, 255, 127));
returnValue = Brushes.Green;
break;
case 2:
returnValue = new SolidColorBrush(Color.FromArgb(255, 255, 215, 00));
returnValue = Brushes.Yellow;
break;
case 3:
returnValue = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
returnValue = Brushes.Aqua;
break;
case 4:
returnValue = Brushes.Red;
break;
default:
break;


+ 1
- 1
BPASmartClient.CustomResource/Themes/MyStyle.xaml 查看文件

@@ -188,7 +188,7 @@
<Setter Property="Source" Value="/BPASmartClient.CustomResource;component/Image/工艺流程.png" />
</Style.Setters>
</Style>
<Style x:Key="imagetop_维护" TargetType="Image">
<Style.Setters>
<Setter Property="Width" Value="20" />


+ 3
- 3
BPASmartClient.Modbus/ModbusTcp.cs 查看文件

@@ -21,8 +21,8 @@ namespace BPASmartClient.Modbus
private ModbusFactory modbusFactory;
private IModbusMaster master;
private TcpClient tcpClient;
private string IPAdress;
private int Port;
public string IPAdress;
public int Port;

public Action ConnectOk { get; set; }

@@ -92,7 +92,7 @@ namespace BPASmartClient.Modbus
Thread.Sleep(3000);
}
}
if (ErrorFlag) MessageLog.GetInstance.Show("ModbusTcp 重连成功!");
if (ErrorFlag && IsReconnect) MessageLog.GetInstance.Show("ModbusTcp 重连成功!");
}

/// <summary>


+ 1
- 0
BPASmartClient.MorkS/ViewModel/DebugViewModel.cs 查看文件

@@ -8,6 +8,7 @@ using BPASmartClient.Model;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using BPASmartClient.EventBus;
using BPASmartClient.MorkS.Model;

namespace BPASmartClient.MorkS.ViewModel
{


+ 45
- 14
DosingSystem/Model/DeviceInquire.cs 查看文件

@@ -1,4 +1,5 @@
using BPASmartClient.Helper;
using BPASmartClient.Message;
using BPASmartClient.Modbus;
using DosingSystem.ViewModel;
using System;
@@ -25,28 +26,33 @@ namespace DosingSystem.Model
ConcurrentDictionary<string, DeviceStatus> DeviceLists = new ConcurrentDictionary<string, DeviceStatus>();
List<string> InvalidIP = new List<string>();

//List<TaskFactory>

public void Init()
{
IpAddressLines();
ThreadManage.GetInstance().StartLong(new Action(() =>
{
if (count >= 255) IpAddressLines();
if (count >= 255)
IpAddressLines();
Thread.Sleep(5000);
}), "配料机设备上线监听", true);
}

public DeviceStatus GetDevice(string deviceName)
public DeviceStatus GetDevice(string ip)
{
if (deviceName != null)
if (ip != null)
{
var res = DeviceLists.Values.FirstOrDefault(p => p.DeviceName == deviceName);
var res = DeviceLists.Values.FirstOrDefault(p => p.IpAddress == ip);
if (res != null) return res;
}
return default;
return new DeviceStatus();
}

private void IpAddressLines()
{


for (int i = 1; i <= 255; i++)
{
if (!InvalidIP.Contains($"{IPSegment}{i}"))
@@ -63,7 +69,10 @@ namespace DosingSystem.Model
private void CompleteCount()
{
lock (_lock)
{
count++;
}

}

private void _myPing_PingCompleted(object sender, PingCompletedEventArgs e)
@@ -74,20 +83,17 @@ namespace DosingSystem.Model
if (!DeviceLists.ContainsKey(ip))
{
DeviceStatus DS = new DeviceStatus();
//DeviceLists.TryAdd(ip, new DeviceStatus());
//DeviceLists[ip].modbusTcp.IsReconnect = false;
//Task.Run(new Action(() => { DeviceLists[ip].modbusTcp.ModbusTcpConnect(ip, 508); }));
DS.modbusTcp.IsReconnect = false;

Task.Run(new Action(() => { DS.modbusTcp.ModbusTcpConnect(ip, 508); }));
DS.modbusTcp.ConnectOk = new Action(() =>
{
//string DeviceName = DeviceLists[ip].modbusTcp.GetString(NameAddress, 20);
string DeviceName = DS.modbusTcp.GetString(NameAddress, 20);
if (DeviceName.Length > 0)
{
DeviceLists.TryAdd(ip, DS);
DeviceLists[ip].Init(DeviceName);
DeviceLists[ip].modbusTcp.IsReconnect = true;
DeviceLists[ip].modbusTcp.IsReconnect = false;
App.Current.Dispatcher.Invoke(new Action(() =>
{
DeviceListViewModel.devices.Add(new Devices()
@@ -95,6 +101,18 @@ namespace DosingSystem.Model
DeviceName = DeviceName,
IpAddress = ip
});

for (int i = 0; i < Json<LocaPar>.Data.Recipes.Count; i++)
{
for (int m = 0; m < Json<LocaPar>.Data.Recipes.ElementAt(i).RawMaterials.Count; m++)
{
if (Json<LocaPar>.Data.Recipes.ElementAt(i).RawMaterials.ElementAt(m).DeviceIp == ip)
{
Json<LocaPar>.Data.Recipes.ElementAt(i).RawMaterials.ElementAt(m).RawMaterialName = DeviceName;
}
}
}

if (!NewRecipeViewModel.RawMaterialNames.Contains(DeviceName))
NewRecipeViewModel.RawMaterialNames.Add(DeviceName);

@@ -109,6 +127,7 @@ namespace DosingSystem.Model
DS.modbusTcp.ConnectFail = new Action(() =>
{
if (!InvalidIP.Contains(ip)) InvalidIP.Add(ip);
MessageLog.GetInstance.Show($"{ip}连接失败");
});

DS.modbusTcp.Disconnect = new Action(() =>
@@ -122,9 +141,9 @@ namespace DosingSystem.Model
if (!NewRecipeViewModel.RawMaterialNames.Contains(res.DeviceName))
NewRecipeViewModel.RawMaterialNames.Remove(res.DeviceName);
}));
//DeviceLists[ip].Dispose();
DS.Dispose();
if (DeviceLists.ContainsKey(ip)) DeviceLists[ip].Dispose();
});

}
}
CompleteCount();
@@ -134,6 +153,7 @@ namespace DosingSystem.Model
public class DeviceStatus
{
public string DeviceName = String.Empty;
public string IpAddress => modbusTcp.IPAdress;
public ModbusTcp modbusTcp = new ModbusTcp();
public void Init(string DeviceName)
{
@@ -143,15 +163,26 @@ namespace DosingSystem.Model
ThreadManage.GetInstance().StartLong(new Action(() =>
{
var res = this.modbusTcp.Read("VW100");
if (res is ushort ushortValue)
if (res != null && res is ushort[] ushortValue)
{
RunStatus = ushortValue;
if (ushortValue.Length >= 1) RunStatus = ushortValue[0];
}
Thread.Sleep(100);
}), $"{DeviceName} 开始监听", true);
}
}

public void SetDeviceName(string name)
{
this.modbusTcp.Write("VW0", new ushort[20]);
this.modbusTcp.SetString("VW0", name);
}

public void StatusReset()
{
this.modbusTcp.Write("VW100", (ushort)1);
}

public void Dispose()
{
ThreadManage.GetInstance().StopTask($"{DeviceName} 开始监听");


+ 41
- 5
DosingSystem/Model/RawMaterialModel.cs 查看文件

@@ -29,6 +29,40 @@ namespace DosingSystem.Model
public float RawMaterialWeight { get { return _mRawMaterialWeight; } set { _mRawMaterialWeight = value; OnPropertyChanged(); } }
private float _mRawMaterialWeight;

/// <summary>
/// 原料类型 MW18
/// 1:液体
/// 2:膏体
/// 3:粉体
/// </summary>
public ushort RawMaterialType { get { return _mRawMaterialType; } set { _mRawMaterialType = value; OnPropertyChanged(); } }
private ushort _mRawMaterialType;

/// <summary>
/// 料仓重量反馈 MD40
/// </summary>
public float WeightFeedback { get { return _mWeightFeedback; } set { _mWeightFeedback = value; OnPropertyChanged(); } }
private float _mWeightFeedback;

/// <summary>
/// 上限反馈
/// </summary>
public bool UpLimtFeedback { get { return _mUpLimtFeedback; } set { _mUpLimtFeedback = value; OnPropertyChanged(); } }
private bool _mUpLimtFeedback;

/// <summary>
/// 下限反馈
/// </summary>
public bool DownLimtFeedback { get { return _mDownLimtFeedback; } set { _mDownLimtFeedback = value; OnPropertyChanged(); } }
private bool _mDownLimtFeedback;

/// <summary>
/// 下料重量反馈 MD52
/// </summary>
public float UpLimtWeightFeedback { get { return _mUpLimtWeightFeedback; } set { _mUpLimtWeightFeedback = value; OnPropertyChanged(); } }
private float _mUpLimtWeightFeedback;


/// <summary>
/// 原料ID
/// </summary>
@@ -37,12 +71,14 @@ namespace DosingSystem.Model

/// <summary>
/// 原料设备执行状态
/// 1:等待下料
/// 2:下料中
/// 3:下料完成
/// 1:准备就绪
/// 2:等待接料
/// 3:接料完成
/// 4:设备异常
/// </summary>
public int RecipeStatus { get { return _mRecipeStatus; } set { _mRecipeStatus = value; OnPropertyChanged(); } }
private int _mRecipeStatus;
[Newtonsoft.Json.JsonIgnore]
public ushort RecipeStatus { get { return _mRecipeStatus; } set { _mRecipeStatus = value; OnPropertyChanged(); } }
private ushort _mRecipeStatus = 1;

}
}

+ 122
- 0
DosingSystem/View/ChangeDeviceNameView.xaml 查看文件

@@ -0,0 +1,122 @@
<Window
x:Class="DosingSystem.View.ChangeDeviceNameView"
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:local="clr-namespace:DosingSystem.View"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:DosingSystem.ViewModel"
Title="ChangeDeviceNameView"
Width="400"
Height="200"
AllowsTransparency="True"
Background="{x:Null}"
Topmost="True"
WindowStartupLocation="CenterScreen"
WindowStyle="None"
mc:Ignorable="d">

<Window.DataContext>
<vm:ChangeDeviceNameViewModel />
</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"
Background="#FF0B2F5F"
BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="0.5*" />
<RowDefinition />
</Grid.RowDefinitions>

<StackPanel
HorizontalAlignment="Center"
VerticalAlignment="Center"
Orientation="Horizontal">
<TextBlock
Margin="10,0,0,0"
Background="Transparent"
FontSize="20"
Foreground="#FF2AB2E7"
Text="请输入新设备名称:" />

<TextBox
Grid.Column="1"
Width="200"
Height="30"
Margin="0,0,7,0"
FontSize="16"
Text="{Binding DeviceName}" />

</StackPanel>

<TextBlock
Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="Transparent"
FontSize="16"
Foreground="Red"
Text="{Binding ErrorInfo}" />

<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>

<Button
Grid.Column="1"
Width="148"
Height="30"
Margin="0,0,7,0"
Command="{Binding ConfirmCommand}"
Content="确认" />

<Button
Name="btClose"
Width="148"
Height="30"
Command="{Binding CancleCommand}"
Content="取消" />

</Grid>

</Grid>
</Border>

</Window>

+ 31
- 0
DosingSystem/View/ChangeDeviceNameView.xaml.cs 查看文件

@@ -0,0 +1,31 @@
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 DosingSystem.View
{
/// <summary>
/// ChangeDeviceNameView.xaml 的交互逻辑
/// </summary>
public partial class ChangeDeviceNameView : Window
{
public ChangeDeviceNameView()
{
InitializeComponent();
ActionManage.GetInstance.CancelRegister("ChangeDeviceNameViewClose");
ActionManage.GetInstance.Register(new Action(() => { this.Close(); }), "ChangeDeviceNameViewClose");
this.br.MouseLeftButtonDown += (o, e) => { if (e.LeftButton == MouseButtonState.Pressed) this.DragMove(); };
}
}
}

+ 117
- 47
DosingSystem/View/DeviceListView.xaml 查看文件

@@ -16,59 +16,129 @@
<vm:DeviceListViewModel />
</UserControl.DataContext>

<UserControl.Resources>
<Style x:Key="UserItemContainerStyle" TargetType="ListBoxItem">
<Style.Resources>
<!-- SelectedItem with focus -->
<SolidColorBrush
x:Key="{x:Static SystemColors.HighlightBrushKey}"
Opacity=".4"
Color="White" />
<!-- SelectedItem without focus -->
<SolidColorBrush
x:Key="{x:Static SystemColors.ControlBrushKey}"
Opacity=".4"
Color="White" />
</Style.Resources>
<!-- 设置触发器 -->
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" Value="White" />
<Setter Property="Foreground" Value="White" />
</Trigger>
<Trigger Property="IsFocused" Value="true">
<Setter Property="Background" Value="White" />
<Setter Property="Foreground" Value="White" />
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>

<Grid>
<ItemsControl
Width="300"
HorizontalAlignment="Left"
ItemsSource="{Binding devices}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border
Margin="0,0,0,15"
BorderBrush="Aqua"
BorderThickness="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>

<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid>
<ListView
Grid.Column="1"
Margin="10"
Background="Transparent"
BorderBrush="#00BEFA"
BorderThickness="0"
ItemsSource="{Binding devices}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid
HorizontalAlignment="Left"
VerticalAlignment="Top"
Columns="4" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>

<ListView.ItemTemplate>
<DataTemplate>
<Border
Name="ShadowElement"
Height="150"
VerticalAlignment="Top"
BorderBrush="#00BEFA"
BorderThickness="2"
ClipToBounds="True"
CornerRadius="8">
<Border.Effect>
<DropShadowEffect
BlurRadius="18"
ShadowDepth="0"
Color="#00BEFA" />
</Border.Effect>

<Grid Margin="20,0,20,0">

<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>

<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>

<TextBlock
Grid.Row="0"
Grid.ColumnSpan="2"
VerticalAlignment="Bottom"
FontSize="40"
Foreground="#00BEFA"
Text="{Binding DeviceName}" />


<TextBlock
HorizontalAlignment="Right"
FontSize="16"
Foreground="Aqua"
Text="IP地址:" />
<StackPanel
Grid.Row="1"
Grid.ColumnSpan="2"
Orientation="Horizontal">
<TextBlock
Grid.Row="1"
FontSize="14"
Foreground="Aqua"
Text="设备IP:" />
<TextBlock
Grid.Row="1"
FontSize="14"
Foreground="Aqua"
Text="{Binding IpAddress}" />
</StackPanel>

<TextBlock
Grid.Column="1"
HorizontalAlignment="Left"
FontSize="16"
Foreground="Aqua"
Text="{Binding IpAddress}" />
<Button
Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="2"
Width="130"
Height="30"
Margin="0,0,0,10"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
Command="{Binding DataContext.ChangeNameCommand, RelativeSource={RelativeSource AncestorType=ListView, Mode=FindAncestor}}"
CommandParameter="{Binding IpAddress}"
Content="修改设备名称"
IsEnabled="{Binding IsEnable}" />

<TextBlock
Grid.Row="1"
HorizontalAlignment="Right"
FontSize="16"
Foreground="Aqua"
Text="设备名称:" />

<TextBlock
Grid.Row="1"
Grid.Column="1"
FontSize="16"
Foreground="Aqua"
Text="{Binding DeviceName}" />
</Grid>
</Border>
</Grid>
</Border>

</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Grid>
</UserControl>

+ 18
- 10
DosingSystem/View/NewRecipeView.xaml 查看文件

@@ -58,11 +58,11 @@
</Border.Background>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="5" />
<RowDefinition />
</Grid.RowDefinitions>

<Button
<!--<Button
Name="btClose"
Margin="0,0,5,0"
Padding="10,5"
@@ -74,6 +74,8 @@
FontSize="18"
Foreground="White" />

<Border BorderBrush="#88DDDDDD" BorderThickness="0,0,0,1" />-->

<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="40" />
@@ -85,7 +87,7 @@
Margin="10,0,0,0"
Background="Transparent"
FontSize="20"
Foreground="#ddd"
Foreground="#FF2AB2E7"
Text="请输入配方名称:" />

<TextBlock
@@ -102,7 +104,6 @@
Orientation="Horizontal">

<TextBox
Name="tbTitle"
Grid.Column="1"
Width="200"
Height="30"
@@ -118,10 +119,17 @@
Content="添加原料" />

<Button
Width="148"
Width="80"
Height="30"
Command="{Binding SaveCommand}"
Content="保存配方" />
Content="确认" />

<Button
Name="btClose"
Width="80"
Height="30"
Margin="7,0,0,0"
Content="取消" />

</StackPanel>

@@ -139,7 +147,7 @@
<ColumnDefinition Width="0.5*" />
</Grid.ColumnDefinitions>

<!--<ComboBox
<ComboBox
Name="cb"
Grid.Column="0"
Margin="3,1"
@@ -153,9 +161,9 @@
ItemsSource="{Binding DataContext.RawMaterialNames, RelativeSource={RelativeSource AncestorType=ItemsControl, Mode=FindAncestor}}"
SelectedIndex="0"
Style="{StaticResource ComboBoxStyle}"
Text="{Binding RawMaterialName}" />-->
Text="{Binding RawMaterialName}" />

<TextBox
<!--<TextBox
Name="cb"
Grid.Column="0"
Margin="3,1"
@@ -165,7 +173,7 @@
FontFamily="楷体"
FontSize="20"
Foreground="#FF2AB2E7"
Text="{Binding RawMaterialName}" />
Text="{Binding RawMaterialName}" />-->
<StackPanel
Grid.Column="1"
VerticalAlignment="Center"


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

@@ -25,6 +25,7 @@ namespace DosingSystem.View
InitializeComponent();
this.btClose.Click += (o, e) => { this.Close(); };
this.br.MouseLeftButtonDown += (o, e) => { if (e.LeftButton == MouseButtonState.Pressed) this.DragMove(); };
ActionManage.GetInstance.CancelRegister("CloseNewRecipeView");
ActionManage.GetInstance.Register(new Action(() => { this.Close(); }), "CloseNewRecipeView");
}
}


+ 4
- 4
DosingSystem/View/RecipeControlView.xaml 查看文件

@@ -145,7 +145,7 @@
<TextBlock
Name="tb"
Foreground="#ddd"
Text="等待下料" />
Text="准备就绪" />
</StackPanel>
<StackPanel Margin="0,0,0,5" Orientation="Horizontal">
<Ellipse
@@ -155,7 +155,7 @@
<TextBlock
Name="tb1"
Foreground="#ddd"
Text="下料中" />
Text="等待接料" />
</StackPanel>
<StackPanel Margin="0,0,0,5" Orientation="Horizontal">
<Ellipse
@@ -165,7 +165,7 @@
<TextBlock
Name="tb2"
Foreground="#ddd"
Text="料完成" />
Text="料完成" />
</StackPanel>
<StackPanel Margin="0,0,0,5" Orientation="Horizontal">
<Ellipse
@@ -175,7 +175,7 @@
<TextBlock
Name="tb3"
Foreground="#ddd"
Text="原料设备异常" />
Text="设备异常" />
</StackPanel>
</StackPanel>
</Grid>


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

@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BPASmartClient.Helper;
using DosingSystem.Model;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;

namespace DosingSystem.ViewModel
{
public class ChangeDeviceNameViewModel : ObservableObject
{
public ChangeDeviceNameViewModel()
{
ActionManage.GetInstance.Register(new Action<object>((o) =>
{
if (o != null && o is string str) IpAddress = str;
}), "ChangeDeviceNameViewOpen");

CancleCommand = new RelayCommand(() => { ActionManage.GetInstance.Send("ChangeDeviceNameViewClose"); });
ConfirmCommand = new RelayCommand(() =>
{
if (string.IsNullOrEmpty(DeviceName))
{
ErrorInfo = "设备名称不能为空";
return;
}
int index = Array.FindIndex(DeviceListViewModel.devices.ToArray(), p => p.IpAddress == IpAddress);
if (index >= 0 && index < DeviceListViewModel.devices.Count)
{
if (DeviceListViewModel.devices.FirstOrDefault(p => p.DeviceName == DeviceName) != null)
ErrorInfo = "设备名称已存在";
else
{
NewRecipeViewModel.RawMaterialNames.Remove(DeviceListViewModel.devices.ElementAt(index).DeviceName);
NewRecipeViewModel.RawMaterialNames.Add(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++)
{
for (int m = 0; m < Json<LocaPar>.Data.Recipes.ElementAt(i).RawMaterials.Count; m++)
{
Json<LocaPar>.Data.Recipes.ElementAt(i).RawMaterials.ElementAt(m).RawMaterialName = DeviceName;
}
}
ActionManage.GetInstance.Send("ChangeDeviceNameViewClose");
}
}

});
}

private static string IpAddress = string.Empty;

public RelayCommand ConfirmCommand { get; set; }

public RelayCommand CancleCommand { get; set; }


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


public string DeviceName { get { return _mDeviceName; } set { _mDeviceName = value; OnPropertyChanged(); } }
private string _mDeviceName;

}
}

+ 12
- 1
DosingSystem/ViewModel/DeviceListViewModel.cs 查看文件

@@ -9,6 +9,7 @@ using System.Collections.ObjectModel;
using System.Windows;
using BPASmartClient.Helper;
using Microsoft.Toolkit.Mvvm.Input;
using DosingSystem.View;

namespace DosingSystem.ViewModel
{
@@ -16,9 +17,19 @@ namespace DosingSystem.ViewModel
{
public DeviceListViewModel()
{

ChangeNameCommand = new RelayCommand<object>((o) =>
{
if (o != null && o is string str)
{
ChangeDeviceNameView cdn = new ChangeDeviceNameView();
ActionManage.GetInstance.Send("ChangeDeviceNameViewOpen", str);
cdn.ShowDialog();
}
});
}

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

public static ObservableCollection<Devices> devices { get; set; } = new ObservableCollection<Devices>();
}



+ 1
- 0
DosingSystem/ViewModel/MainViewModel.cs 查看文件

@@ -38,6 +38,7 @@ namespace DosingSystem.ViewModel

public MainViewModel()
{
Json<LocaPar>.Read();
TogglePag = new RelayCommand<object>(DoNavChanged);
Login = new RelayCommand(() => { DoNavChanged("AdminstratorsView.用户登录"); UserManagement = false; });
PasswordChange = new RelayCommand(() =>


+ 8
- 1
DosingSystem/ViewModel/NewRecipeViewModel.cs 查看文件

@@ -53,6 +53,12 @@ namespace DosingSystem.ViewModel

SaveCommand = new RelayCommand(() =>
{
for (int i = 0; i < RawMaterials.Count; i++)
{
var res = DeviceListViewModel.devices.FirstOrDefault(p => p.DeviceName == RawMaterials.ElementAt(i).RawMaterialName);
if (res != null) RawMaterials.ElementAt(i).DeviceIp = res.IpAddress;
}

if (RecipCode.Length <= 0)
{
var res = Array.FindIndex(Json<LocaPar>.Data.Recipes.ToArray(), p => p.RecipeName == RecipeName);
@@ -72,6 +78,7 @@ namespace DosingSystem.ViewModel
if (res >= 0 && res < Json<LocaPar>.Data.Recipes.Count)
{
Json<LocaPar>.Data.Recipes.ElementAt(res).RecipeName = RecipeName;
Json<LocaPar>.Data.Recipes.ElementAt(res).RawMaterials.Clear();
foreach (var item in RawMaterials)
{
Json<LocaPar>.Data.Recipes.ElementAt(res).RawMaterials.Add(item);
@@ -94,7 +101,7 @@ namespace DosingSystem.ViewModel
SerialNum = Json<LocaPar>.Data.Recipes.Count + 1,
RawMaterials = RawMaterials,
RecipCode = sb.ToString(),
RecipeName = RecipeName
RecipeName = RecipeName,
});
}



+ 27
- 1
DosingSystem/ViewModel/RecipeControlViewModel.cs 查看文件

@@ -10,6 +10,7 @@ using System.Windows;
using BPASmartClient.Helper;
using Microsoft.Toolkit.Mvvm.Input;
using DosingSystem.Model;
using System.Threading;

namespace DosingSystem.ViewModel
{
@@ -30,13 +31,38 @@ namespace DosingSystem.ViewModel
Recipes.ElementAt(index).IsEnable = false;
foreach (var item in Recipes.ElementAt(index).RawMaterials)
{
DeviceInquire.GetInstance.GetDevice(item.RawMaterialName)?.Start(item.RawMaterialWeight);//启动写入
DeviceInquire.GetInstance.GetDevice(item.DeviceIp)?.Start(item.RawMaterialWeight);//启动写入
}
}
}));
}
});


ThreadManage.GetInstance().StartLong(new Action(() =>
{
for (int i = 0; i < Recipes.Count; i++)
{
for (int m = 0; m < Recipes.ElementAt(i).RawMaterials.Count; m++)
{
var RunStatus = DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(m).DeviceIp).RunStatus;
Recipes.ElementAt(i).RawMaterials.ElementAt(m).RecipeStatus = RunStatus;
var res = Recipes.ElementAt(i).RawMaterials.Where(p => p.RecipeStatus == 3).ToList();
if (res != null && res.Count == Recipes.ElementAt(i).RawMaterials.Count)
{
for (int r = 0; r < Recipes.ElementAt(i).RawMaterials.Count; r++)
{
DeviceInquire.GetInstance.GetDevice(Recipes.ElementAt(i).RawMaterials.ElementAt(r).DeviceIp).StatusReset();
}
Recipes.ElementAt(i).IsEnable = true;
}
}
}
Thread.Sleep(100);
}), "RecipeControlViewModelStatusInquire");

}

public RelayCommand<object> StartCommand { get; set; }
public ObservableCollection<RecipeModel> Recipes { get; set; }
}


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

@@ -18,7 +18,7 @@ namespace DosingSystem.ViewModel
{
public RecipeSettingsViewModel()
{
Json<LocaPar>.Read();
//Json<LocaPar>.Read();
Recipes = Json<LocaPar>.Data.Recipes;
NewRecipe = new Action(() =>
{


正在加载...
取消
保存