Browse Source

页面显示设备状态逻辑修改

master
sc 4 months ago
parent
commit
6eae137bd1
  1. 43
      ConvertMoels/StatexmlConvert.cs
  2. 9
      Properties/Resources.Designer.cs
  3. 3
      Properties/Resources.en-US.resx
  4. 3
      Properties/Resources.resx
  5. 3
      Properties/Resources.zh-CN.resx
  6. 9
      Properties/Resources.zh-TW.resx
  7. 1
      SunlightCentralizedControlManagement_SCCM_.csproj
  8. 2
      UserClass/AsyncTcpClient.cs
  9. 25
      View/CurveView.xaml
  10. 29
      View/MachinesView.xaml
  11. 265
      View/MachinesView.xaml.cs
  12. 29
      View/MonitorView.xaml
  13. 77
      View/MonitorView.xaml.cs
  14. 48
      ViewModel/MainWindowViewModel.cs
  15. 130
      ViewModel/MonitorViewModel.cs

43
ConvertMoels/StatexmlConvert.cs

@ -0,0 +1,43 @@
using ScottPlot.TickGenerators.Financial;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
namespace SunlightCentralizedControlManagement_SCCM_.ConvertMoels
{
internal class StatexmlConvert : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
{
return null;
}
else
{
string Staten = "None";
string i = value.ToString();
if (i == "101") Staten = "Walk";//运行
else if (i == "202") Staten = "RunFast";//运行
else if (i == "301") Staten = "Stop";//完成
else if (i == "309") Staten = "ErrorOutline";//错误
else if (i == "800") Staten = "LinkOff";//未连接
else if (i == "801") Staten = "Link";//连接成功
else if (i == "899") Staten = "LinkOff";//关闭连接
else if (i == "TRUE") Staten = "Lock";//锁
return Staten;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

9
Properties/Resources.Designer.cs

@ -2607,6 +2607,15 @@ namespace SunlightCentralizedControlManagement_SCCM_.Properties {
}
}
/// <summary>
/// 查找类似 The machine is not ready 的本地化字符串。
/// </summary>
public static string TMNR {
get {
return ResourceManager.GetString("TMNR", resourceCulture);
}
}
/// <summary>
/// 查找类似 Today 的本地化字符串。
/// </summary>

3
Properties/Resources.en-US.resx

@ -1047,4 +1047,7 @@
<data name="powder" xml:space="preserve">
<value>Powder</value>
</data>
<data name="TMNR" xml:space="preserve">
<value>The machine is not ready</value>
</data>
</root>

3
Properties/Resources.resx

@ -1047,4 +1047,7 @@
<data name="powder" xml:space="preserve">
<value>powder</value>
</data>
<data name="TMNR" xml:space="preserve">
<value>The machine is not ready</value>
</data>
</root>

3
Properties/Resources.zh-CN.resx

@ -1047,4 +1047,7 @@
<data name="powder" xml:space="preserve">
<value>粉体</value>
</data>
<data name="TMNR" xml:space="preserve">
<value>机台未就绪</value>
</data>
</root>

9
Properties/Resources.zh-TW.resx

@ -1039,12 +1039,15 @@
<value>機台不存在</value>
</data>
<data name="dye" xml:space="preserve">
<value />
<value>染料</value>
</data>
<data name="chemicals" xml:space="preserve">
<value />
<value>助劑</value>
</data>
<data name="powder" xml:space="preserve">
<value />
<value>粉體</value>
</data>
<data name="TMNR" xml:space="preserve">
<value>機台未就緒</value>
</data>
</root>

1
SunlightCentralizedControlManagement_SCCM_.csproj

@ -103,6 +103,7 @@
<Compile Include="ConvertMoels\BoolRBConvert.cs" />
<Compile Include="ConvertMoels\StatenClassConvert.cs" />
<Compile Include="ConvertMoels\BoolToVisidilityConvert.cs" />
<Compile Include="ConvertMoels\StatexmlConvert.cs" />
<Compile Include="EX\DispenseState.xaml.cs">
<DependentUpon>DispenseState.xaml</DependentUpon>
</Compile>

2
UserClass/AsyncTcpClient.cs

@ -66,7 +66,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.UserClass
{
DataRow drEmployee = MainWindowViewModel.Machines.Select("IP='" + client.IP + "'").First();
drEmployee.BeginEdit();
drEmployee["State"] = "899";
drEmployee["State"] = "800";
drEmployee["WorkOrder"] = "------";
drEmployee["Dyelot"] = "";
drEmployee["Temperature"] = "---.-";

25
View/CurveView.xaml

@ -13,6 +13,7 @@
Loaded="UserControl_Loaded"
d:DesignHeight="900" d:DesignWidth="1800">
<UserControl.Resources>
<ConvertMoels:StatexmlConvert x:Key="StatexmlConvert"/>
<ConvertMoels:StateToColorConvert x:Key="StateToColorConvert"/>
</UserControl.Resources>
<Grid>
@ -21,7 +22,7 @@
GridLinesVisibility="All" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" FontSize="15"
Grid.ColumnSpan="2" CanUserResizeRows="False" AutoGenerateColumns="False" MinColumnWidth="30"
CanUserAddRows="False" CanUserDeleteRows="False" HeadersVisibility ="Column" SelectionMode="Single"
Margin="0,0,0,60" HorizontalAlignment="Right" Width="300" MouseDoubleClick="Griddata_MouseDoubleClick">
Margin="0,0,0,60" HorizontalAlignment="Right" Width="330" MouseDoubleClick="Griddata_MouseDoubleClick">
<DataGrid.RowStyle >
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Height" Value="30" />
@ -52,11 +53,23 @@
</DataGrid.CellStyle>
<DataGrid.Columns>
<!--列信息绑定-->
<DataGridTemplateColumn Width="70" Header="{x:Static lang:Resources.State}">
<DataGridTemplateColumn Width="100" Header="{x:Static lang:Resources.State}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<materialDesign:PackIcon Kind="StateMachine" Width="25" Height="30" VerticalAlignment="Center" HorizontalAlignment="Center"
Foreground="{Binding Path=State,Converter={StaticResource StateToColorConvert}}"/>
<UniformGrid VerticalAlignment="Bottom" HorizontalAlignment="Left">
<Border>
<Grid>
<StackPanel Width="100" Orientation="Horizontal">
<materialDesign:PackIcon Width="25" Height="30"
Kind="{Binding Path=State,Converter={StaticResource StatexmlConvert}}"
Foreground="{Binding Path=State,Converter={StaticResource StateToColorConvert}}"/>
<materialDesign:PackIcon Width="25" Height="30"
Kind="{Binding Path=LOCK,Converter={StaticResource StatexmlConvert}}"
Foreground="{Binding Path=State,Converter={StaticResource StateToColorConvert}}"/>
</StackPanel>
</Grid>
</Border>
</UniformGrid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
@ -68,7 +81,7 @@
GridLinesVisibility="All" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" FontSize="15"
Grid.ColumnSpan="2" CanUserResizeRows="False" AutoGenerateColumns="False" MinColumnWidth="30"
CanUserAddRows="False" CanUserDeleteRows="False" HeadersVisibility ="Column" SelectionMode="Single"
VerticalAlignment="Top" Height="500" Margin="0,0,300,0" MouseDoubleClick="GridWorkOrder_MouseDoubleClick" >
VerticalAlignment="Top" Height="500" Margin="0,0,330,0" MouseDoubleClick="GridWorkOrder_MouseDoubleClick" >
<DataGrid.RowStyle >
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Height" Value="30" />
@ -165,7 +178,7 @@
</ListView>
</StackPanel>
<Grid Background="White" Margin="0,500,300,60">
<Grid Background="White" Margin="0,500,330,60">
<ContentControl x:Name="Picture"/>
</Grid>
</Grid>

29
View/MachinesView.xaml

@ -9,11 +9,12 @@
xmlns:ConvertMoels="clr-namespace:SunlightCentralizedControlManagement_SCCM_.ConvertMoels"
xmlns:localUserClass="clr-namespace:DyeingComputer.UserClass"
xmlns:viewmodel="clr-namespace:SunlightCentralizedControlManagement_SCCM_.ViewModel"
d:DataContext="{d:DesignInstance Type=viewmodel:MainWindowViewModel}"
d:DataContext="{d:DesignInstance Type=local:MachinesView}"
mc:Ignorable="d"
Loaded="UserControl_Loaded"
d:DesignHeight="900" d:DesignWidth="1200">
<UserControl.Resources>
<ConvertMoels:StatexmlConvert x:Key="StatexmlConvert"/>
<ConvertMoels:StateToColorConvert x:Key="StateToColorConvert"/>
<ConvertMoels:BoolRBConvert x:Key="BoolRBConvert"/>
<ConvertMoels:IORBConvert x:Key="IORBConvert"/>
@ -23,13 +24,13 @@
<RowDefinition/>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<DataGrid Grid.Row="0" x:Name="Griddata" AlternationCount="2" IsReadOnly="True" d:ItemsSource="{d:SampleData ItemCount=999}"
ItemsSource="{Binding Path=TechnologicalMachine_View,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
<DataGrid Grid.Row="0" x:Name="Griddata" AlternationCount="2" IsReadOnly="True" d:ItemsSource="{d:SampleData ItemCount=999}"
ItemsSource="{Binding Path=TechnologicalMachine_View,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Background="White" GridLinesVisibility="All" ColumnHeaderHeight="40" HorizontalContentAlignment="Right"
CanUserReorderColumns="False" CanUserSortColumns="False" CanUserResizeRows="False" CanUserResizeColumns="False"
CanUserDeleteRows="False" SelectionMode="Single" FontSize="15" Focusable="True"
AutoGenerateColumns="False" MinColumnWidth="30"
HorizontalAlignment="Left" Width="280" MouseDoubleClick="Griddata_MouseDoubleClick">
HorizontalAlignment="Left" Width="310" MouseDoubleClick="Griddata_MouseDoubleClick">
<DataGrid.RowStyle >
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Height" Value="30" />
@ -68,18 +69,30 @@
</DataGrid.Resources>
<DataGrid.Columns>
<!--列信息绑定-->
<DataGridTemplateColumn Width="70" Header="{x:Static lang:Resources.State}">
<DataGridTemplateColumn Width="100" Header="{x:Static lang:Resources.State}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<materialDesign:PackIcon Kind="StateMachine" Width="25" Height="30" VerticalAlignment="Center" HorizontalAlignment="Center"
Foreground="{Binding Path=State,Converter={StaticResource StateToColorConvert}}"/>
<UniformGrid VerticalAlignment="Bottom" HorizontalAlignment="Left">
<Border>
<Grid>
<StackPanel Width="100" Orientation="Horizontal">
<materialDesign:PackIcon Width="25" Height="30"
Kind="{Binding Path=State,Converter={StaticResource StatexmlConvert}}"
Foreground="{Binding Path=State,Converter={StaticResource StateToColorConvert}}"/>
<materialDesign:PackIcon Width="25" Height="30"
Kind="{Binding Path=LOCK,Converter={StaticResource StatexmlConvert}}"
Foreground="{Binding Path=State,Converter={StaticResource StateToColorConvert}}"/>
</StackPanel>
</Grid>
</Border>
</UniformGrid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="{x:Static lang:Resources.Machine}" Binding="{Binding Name}" Width="210" IsReadOnly="True"/>
</DataGrid.Columns>
</DataGrid>
<Grid Grid.Row="0" Margin="280,0,0,0">
<Grid Grid.Row="0" Margin="310,0,0,0">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="5"/>

265
View/MachinesView.xaml.cs

@ -4,11 +4,14 @@ using SunlightCentralizedControlManagement_SCCM_.ViewModel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
@ -23,16 +26,34 @@ using System.Windows.Shapes;
using System.Windows.Threading;
using TouchSocket.Core;
using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper;
using static SunlightCentralizedControlManagement_SCCM_.ViewModel.MainWindowViewModel;
namespace SunlightCentralizedControlManagement_SCCM_.View
{
/// <summary>
/// MachinesSet.xaml 的交互逻辑
/// </summary>
public partial class MachinesView : UserControl
public partial class MachinesView : UserControl, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
if (propertyName != null)
{
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
public MachinesView()
{
DataContext = this;
InitializeComponent();
CountDown();
}
@ -42,7 +63,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
private readonly UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "SCCM.ini");
//private string SYS_machines = null;
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
{
}
string machine;
private void Griddata_MouseDoubleClick(object sender, MouseButtonEventArgs e)
@ -115,12 +137,12 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
SQLiteHelpers.Close();//关闭数据库
}
IO_data();//重新获得io表
MainWindowViewModel.D_view = true;
D_view = true;
}
private void Grid_D_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
{
MainWindowViewModel.D_view = false;
D_view = false;
}
private void Grid_A_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
@ -140,12 +162,12 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
SQLiteHelpers.Update("IOName", datagrid_v, "ID ='" + ID + "'", null);//更新
SQLiteHelpers.Close();//关闭数据库
}
MainWindowViewModel.A_view = true;
A_view = true;
}
private void Grid_A_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
{
MainWindowViewModel.A_view = false;
A_view = false;
}
private void SYS_Grid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
@ -168,7 +190,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
DAT = "SC862" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", "ID='" + index + "'") + datagrid_v.ToJsonString()
});//发送862指令修改系统设置
}
MainWindowViewModel.SysSet_view = true;
SysSet_view = true;
}
private void SET_Grid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
@ -191,17 +213,17 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
DAT = "SC861" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", "ID='" + index + "'") +datagrid_v.ToJsonString()
});//发送861指令修改程序设置
}
MainWindowViewModel.ParameterSet_view = true;
ParameterSet_view = true;
}
private void SYS_Grid_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
{
MainWindowViewModel.SysSet_view = false;
SysSet_view = false;
}
private void SET_Grid_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
{
MainWindowViewModel.ParameterSet_view = false;
ParameterSet_view = false;
}
private int view = 0;
@ -261,8 +283,227 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
timer1s.Start();
}//时间周期初始化
void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S
{ IO_data(); }
{
IO_data();
DATA_view();
}
private async void DATA_view()//IO显示
{
await Task.Run(() =>
{
try
{
if (dt_m.Rows.Count >= 0)
{
SYSData_M = ToObservableCollection<DATA_M>(dt_m);
}
}
catch (Exception) { }
try
{
if (dt_a.Rows.Count >= 0)
{
if ((bool)A_view) SYSData_A = ToObservableCollection<DATA_A>(dt_a);
}
}
catch (Exception) { }
try
{
if (dt_d.Rows.Count >= 0)
{
if ((bool)D_view) SYSData_D = ToObservableCollection<DATA_D>(dt_d);
}
}
catch (Exception) { }
try
{
TechnologicalMachine_View = ToObservableCollection<TechnologicalM>(Machines);
}
catch (Exception) { }
try
{
if (dt_ParameterSet.Rows.Count >= 0)
{
if (ParameterSet_view) Paramete_Set = ToObservableCollection<ParameterSet>(dt_ParameterSet);
}
}
catch (Exception) { }
try
{
if (dt_SysSet.Rows.Count >= 0)
{
if (SysSet_view) Sys_Set = ToObservableCollection<SysSet>(dt_SysSet);
}
}
catch (Exception) { }
});
}
bool A_view =true;
bool D_view =true;
bool ParameterSet_view = true;
bool SysSet_view = true;
ObservableCollection<DATA_A> sysData_A = new ObservableCollection<DATA_A>();
ObservableCollection<DATA_D> sysData_D = new ObservableCollection<DATA_D>();
ObservableCollection<DATA_M> sysData_M = new ObservableCollection<DATA_M>();
ObservableCollection<ParameterSet> paramete_Set = new ObservableCollection<ParameterSet>();
ObservableCollection<SysSet> sys_Set = new ObservableCollection<SysSet>();
ObservableCollection<TechnologicalM> technologicalMachine_View = new ObservableCollection<TechnologicalM>();
public ObservableCollection<DATA_A> SYSData_A
{
get { return sysData_A; }
set
{
sysData_A = value;
RaisePropertyChanged("SYSData_A");
}
}
public ObservableCollection<DATA_D> SYSData_D
{
get { return sysData_D; }
set
{
sysData_D = value;
RaisePropertyChanged("SYSData_D");
}
}
public ObservableCollection<DATA_M> SYSData_M
{
get { return sysData_M; }
set
{
sysData_M = value;
RaisePropertyChanged("SYSData_M");
}
}
public ObservableCollection<TechnologicalM> TechnologicalMachine_View
{
get { return technologicalMachine_View; }
set
{
technologicalMachine_View = value;
RaisePropertyChanged("TechnologicalMachine_View");
}
}
public ObservableCollection<ParameterSet> Paramete_Set
{
get { return paramete_Set; }
set
{
paramete_Set = value;
RaisePropertyChanged("Paramete_Set");
}
}
public ObservableCollection<SysSet> Sys_Set
{
get { return sys_Set; }
set
{
sys_Set = value;
RaisePropertyChanged("Sys_Set");
}
}
public class DATA_A
{
public string IOName { get; set; }
public int AIO { get; set; }
public string ID { get; set; }
public string PLC { get; set; }
public string type { get; set; }
}
public class DATA_D
{
public string IOName { get; set; }
public bool DIO { get; set; }
public string ID { get; set; }
public string PLC { get; set; }
public string type { get; set; }
}
public class DATA_M
{
public string IOName { get; set; }
public double Value { get; set; }
public string ID { get; set; }
public string PLC { get; set; }
public string type { get; set; }
}
public class TechnologicalM
{
public string Name { get; set; }
public string WorkOrder { get; set; }
public string Dyelot { get; set; }
public string Temperature { get; set; }
public string WaterLevel { get; set; }
public string Process { get; set; }
public string Step { get; set; }
public string Message { get; set; }
public string State { get; set; }
public string LOCK { get; set; }
}
public class ParameterSet
{
public string Category { get; set; }
public string ParameterID { get; set; }
public string ParameterName { get; set; }
public string Value { get; set; }
}
public class SysSet
{
public string Category { get; set; }
public string ParameterID { get; set; }
public string ParameterName { get; set; }
public string Value { get; set; }
}
public ObservableCollection<T> ToObservableCollection<T>(DataTable dt) where T : class, new()
{
Type t = typeof(T);
PropertyInfo[] propertys = t.GetProperties();
ObservableCollection<T> lst = new ObservableCollection<T>();
string typeName = string.Empty;
foreach (DataRow dr in dt.Rows)
{
T entity = new T();
foreach (PropertyInfo pi in propertys)
{
typeName = pi.Name;
if (dt.Columns.Contains(typeName))
{
if (!pi.CanWrite) continue;
object value = dr[typeName];
if (value == DBNull.Value) continue;
if (pi.PropertyType == typeof(string))
{
pi.SetValue(entity, value.ToString(), null);
}
else if (pi.PropertyType == typeof(int) || pi.PropertyType == typeof(int?))
{
pi.SetValue(entity, int.Parse(value.ToString()), null);
}
else if (pi.PropertyType == typeof(DateTime?) || pi.PropertyType == typeof(DateTime))
{
pi.SetValue(entity, DateTime.Parse(value.ToString()), null);
}
else if (pi.PropertyType == typeof(float))
{
pi.SetValue(entity, float.Parse(value.ToString()), null);
}
else if (pi.PropertyType == typeof(double))
{
pi.SetValue(entity, double.Parse(value.ToString()), null);
}
else
{
pi.SetValue(entity, value, null);
}
}
}
lst.Add(entity);
}
return lst;
}
}
}

29
View/MonitorView.xaml

@ -13,6 +13,7 @@
mc:Ignorable="d"
d:DesignHeight="1000" d:DesignWidth="1900">
<UserControl.Resources>
<ConvertMoels:StatexmlConvert x:Key="StatexmlConvert"/>
<ConvertMoels:StateToColorConvert x:Key="StateToColorConvert"/>
<ConvertMoels:BoolToVisidilityConvert x:Key="BoolToVisidilityConvert"/>
</UserControl.Resources>
@ -23,7 +24,8 @@
<RowDefinition/>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<DataGrid Grid.Row="0" Grid.Column="0" x:Name="Griddata" AlternationCount="2" IsReadOnly="True" SelectionChanged="Griddata_SelectionChanged"
<DataGrid Grid.Row="0" Grid.Column="0" x:Name="Griddata" AlternationCount="2" IsReadOnly="True"
SelectionChanged="Griddata_SelectionChanged"
d:ItemsSource="{d:SampleData ItemCount=999}" AutoGenerateColumns="False" MinColumnWidth="30"
ItemsSource="{Binding Path=TechnologicalMachine_View,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Background="White" GridLinesVisibility="All" ColumnHeaderHeight="40" HorizontalContentAlignment="Right"
@ -33,6 +35,7 @@
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="Height" Value="30" />
<Setter Property="FontSize" Value="25" />
<Setter Property="VerticalAlignment" Value="Center"/>
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="#FFFFFFFF" />
@ -42,7 +45,7 @@
</Trigger>
<Trigger Property="IsMouseOver" Value="False"/>
<DataTrigger Binding="{Binding State}" Value="309">
<Setter Property="Background" Value="Red"/>
<Setter Property="Background" Value="Yellow"/>
</DataTrigger>
</Style.Triggers>
</Style>
@ -51,6 +54,7 @@
<Style TargetType="DataGridCell">
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="MinWidth" Value="20"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#FFC0C0C0"/>
@ -70,11 +74,24 @@
</DataGrid.Resources>
<DataGrid.Columns>
<!--列信息绑定-->
<DataGridTemplateColumn Width="70" Header="{x:Static lang:Resources.State}">
<DataGridTextColumn Binding="{Binding State}" Width="0" MaxWidth="0" IsReadOnly="True"/>
<DataGridTemplateColumn Width="100" Header="{x:Static lang:Resources.State}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<materialDesign:PackIcon Kind="StateMachine" Width="25" Height="30" VerticalAlignment="Center" HorizontalAlignment="Center"
Foreground="{Binding Path=State,Converter={StaticResource StateToColorConvert}}"/>
<DataTemplate>
<UniformGrid VerticalAlignment="Bottom" HorizontalAlignment="Left">
<Border>
<Grid>
<StackPanel Width="100" Orientation="Horizontal">
<materialDesign:PackIcon Width="25" Height="30"
Kind="{Binding Path=State,Converter={StaticResource StatexmlConvert}}"
Foreground="{Binding Path=State,Converter={StaticResource StateToColorConvert}}"/>
<materialDesign:PackIcon Width="25" Height="30"
Kind="{Binding Path=LOCK,Converter={StaticResource StatexmlConvert}}"
Foreground="{Binding Path=State,Converter={StaticResource StateToColorConvert}}"/>
</StackPanel>
</Grid>
</Border>
</UniformGrid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

77
View/MonitorView.xaml.cs

@ -1,4 +1,6 @@
 using SkiaSharp;
using LiveChartsCore.Geo;
using SkiaSharp;
using SunlightCentralizedControlManagement_SCCM_.UserClass;
using SunlightCentralizedControlManagement_SCCM_.ViewModel;
using SunlightCentralizedControlManagement_SCCM_.WindowsView;
using System;
@ -8,6 +10,7 @@ using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@ -21,15 +24,13 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using VncSharpWpf;
using System.Xml.Linq;
using TouchSocket.Core;
using TouchSocket.Sockets;
using VncSharpWpf;
using static SunlightCentralizedControlManagement_SCCM_.WindowsView.ViewStep;
using static System.Net.WebRequestMethods;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar;
using SunlightCentralizedControlManagement_SCCM_.UserClass;
using System.Net.NetworkInformation;
namespace SunlightCentralizedControlManagement_SCCM_.View
{
@ -74,36 +75,51 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
private string dyelot;
private int machines_info=0;
public static string Sys_log;
private void Griddata_SelectionChanged(object sender, SelectionChangedEventArgs e)//设备列表
{
Stop.IsEnabled = true;
Paused.IsEnabled = true;
Insert.IsEnabled = false;
edit.IsEnabled = false;
Resume.IsEnabled = false;
Delete.IsEnabled = false;
Jump.IsEnabled = false;
DyeingMachine.IsEnabled = true;
Curve.IsEnabled = true;
Screen.IsEnabled = true;
Receipt.IsEnabled = true;
LOCK_XML.IsEnabled = true;
TechnologicalProcess_bool = true;
IsInteractive = false;
int rownum = Griddata.SelectedIndex;//获取鼠标选中行并定义变量
string mac_s = "800";
if (rownum != -1)//判断鼠标定位是否有效
{
machine = (Griddata.Columns[1].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第1列,
workOrder = (Griddata.Columns[2].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第列,
dyelot = (Griddata.Columns[3].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第列,
MainWindowViewModel.machine = machine;
MainWindowViewModel.workOrder= workOrder;
MainWindowViewModel.dyelot= dyelot;
MainWindowViewModel.machin_LOG = Properties.Resources.Machine + ":" + machine + " " + Properties.Resources.WorkOrder + ":" + workOrder;
machin_LOG.Text = MainWindowViewModel.machin_LOG;
mac_s = (Griddata.Columns[0].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第1列,
}
else { return; }
if ((mac_s != "800") && (mac_s != "801") && (mac_s != "802"))
{
Stop.IsEnabled = true;
Paused.IsEnabled = true;
Insert.IsEnabled = false;
edit.IsEnabled = false;
Resume.IsEnabled = false;
Delete.IsEnabled = false;
Jump.IsEnabled = false;
DyeingMachine.IsEnabled = true;
Curve.IsEnabled = true;
Screen.IsEnabled = true;
Receipt.IsEnabled = true;
LOCK_XML.IsEnabled = true;
TechnologicalProcess_bool = true;
IsInteractive = false;
if (rownum != -1)//判断鼠标定位是否有效
{
machine = (Griddata.Columns[2].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第1列,
workOrder = (Griddata.Columns[3].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第列,
dyelot = (Griddata.Columns[4].GetCellContent(Griddata.Items[rownum]) as TextBlock).Text;//定位第列,
MainWindowViewModel.machine = machine;
MainWindowViewModel.workOrder = workOrder;
MainWindowViewModel.dyelot = dyelot;
MainWindowViewModel.machin_LOG = Properties.Resources.Machine + ":" + machine + " " + Properties.Resources.WorkOrder + ":" + workOrder;
machin_LOG.Text = MainWindowViewModel.machin_LOG;
}
}
else
{
MessageBox.Show(Properties.Resources.TMNR, "800", MessageBoxButton.OK, MessageBoxImage.Information); //
}
}
@ -626,7 +642,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
public string Process { get; set; }
public string Step { get; set; }
public string Message { get; set; }
public string State { get; set; }
public string State { get; set; }
public string LOCK { get; set; }
}
public class TechnologicalP

48
ViewModel/MainWindowViewModel.cs

@ -238,13 +238,13 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
DAT = "SC830" + Selet_Machines(Machines, "SYSKEY", "ID='" + i + "'").ToString()
});//信息插入队列
string mode = Machines.Select("NAME='" + machine + "'").First().Field<string>("LOCK");
string mode = Machines.Select("ID='" + i + "'").First().Field<string>("LOCK");//发送锁定状态
if (mode == "TRUE")
{
Dictionary<string, object> dat_821 = new Dictionary<string, object>();
dat_821.Clear();
dat_821.Add("LOCK", "TRUE");
DataRow drEmployee = Machines.Select("NAME='" + machine + "'").First();
DataRow drEmployee = Machines.Select("ID='" + i + "'").First();
int index = Convert.ToInt16(drEmployee.Field<object>("ID"));
stringQueue.Enqueue(new QueueString
{
@ -259,7 +259,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
for (int i = 0; i < Machinesdata_Count; i++)
{
string mac_s = Selet_Machines(Machines, "State", "ID='" + i + "'").ToString();
if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "309"))//获取信息
if ((mac_s == "101") || (mac_s == "201") || (mac_s == "202") || (mac_s == "301") || (mac_s == "309"))//获取信息
{
stringQueue.Enqueue(new QueueString
{
@ -397,11 +397,11 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
public static DataTable dt_ParameterSet = new DataTable();
public static DataTable dt_SysSet = new DataTable();
public static bool TechnologicalProcess_bool =true;
public static bool A_view =true;
public static bool D_view =true;
// public static bool A_view =true;
// public static bool D_view =true;
public static bool IO_view;
public static bool ParameterSet_view=true;
public static bool SysSet_view=true;
// public static bool ParameterSet_view=true;
// public static bool SysSet_view=true;
public static string machine;
public static string workOrder;
public static string dyelot;
@ -411,7 +411,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
await Task.Run(() =>
{
try
/* try
{
if (dt_m.Rows.Count >= 0)
{
@ -434,13 +434,13 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
if ((bool)D_view) SYSData_D = ToObservableCollection<DATA_D>(dt_d);
}
}
catch (Exception) { }
catch (Exception) { }*/
/* try
{
TechnologicalMachine_View = ToObservableCollection<TechnologicalM>(Machines);
}
catch (Exception) { }*/
try
/* try
{
if (dt_ParameterSet.Rows.Count >= 0)
{
@ -455,7 +455,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
if (SysSet_view) Sys_Set = ToObservableCollection<SysSet>(dt_SysSet);
}
}
catch (Exception) { }
catch (Exception) { }*/
/* try
{
if (dt_TP.Rows.Count >= 0)
@ -468,14 +468,14 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
});
}
ObservableCollection<DATA_A> sysData_A = new ObservableCollection<DATA_A>();
ObservableCollection<DATA_D> sysData_D = new ObservableCollection<DATA_D>();
ObservableCollection<DATA_M> sysData_M = new ObservableCollection<DATA_M>();
ObservableCollection<ParameterSet> paramete_Set = new ObservableCollection<ParameterSet>();
ObservableCollection<SysSet> sys_Set = new ObservableCollection<SysSet>();
// ObservableCollection<DATA_A> sysData_A = new ObservableCollection<DATA_A>();
// ObservableCollection<DATA_D> sysData_D = new ObservableCollection<DATA_D>();
// ObservableCollection<DATA_M> sysData_M = new ObservableCollection<DATA_M>();
// ObservableCollection<ParameterSet> paramete_Set = new ObservableCollection<ParameterSet>();
// ObservableCollection<SysSet> sys_Set = new ObservableCollection<SysSet>();
//ObservableCollection<TechnologicalP> technologicalProcess_View = new ObservableCollection<TechnologicalP>();
//ObservableCollection<TechnologicalM> technologicalMachine_View = new ObservableCollection<TechnologicalM>();
public ObservableCollection<DATA_A> SYSData_A
/* public ObservableCollection<DATA_A> SYSData_A
{
get { return sysData_A; }
@ -503,7 +503,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
sysData_M = value;
RaisePropertyChanged("SYSData_M");
}
}
}*/
/* public ObservableCollection<TechnologicalP> TechnologicalProcess_View
{
get { return technologicalProcess_View; }
@ -522,7 +522,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
RaisePropertyChanged("TechnologicalMachine_View");
}
}*/
public ObservableCollection<ParameterSet> Paramete_Set
/* public ObservableCollection<ParameterSet> Paramete_Set
{
get { return paramete_Set; }
set
@ -539,8 +539,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
sys_Set = value;
RaisePropertyChanged("Sys_Set");
}
}
public class DATA_A
}*/
/* public class DATA_A
{
public string IOName { get; set; }
public int AIO { get; set; }
@ -563,7 +563,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
public string ID { get; set; }
public string PLC { get; set; }
public string type { get; set; }
}
}*/
/* public class TechnologicalM
{
public string Name { get; set; }
@ -592,7 +592,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
public string Parameter5 { get; set; }
public string DYELOT { get; set; }
}*/
public class ParameterSet
/* public class ParameterSet
{ public string Category { get; set; }
public string ParameterID { get; set; }
public string ParameterName { get; set; }
@ -605,7 +605,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
public string ParameterID { get; set; }
public string ParameterName { get; set; }
public string Value { get; set; }
}
}*/
public ObservableCollection<T> ToObservableCollection<T>(DataTable dt) where T : class, new()
{
Type t = typeof(T);

130
ViewModel/MonitorViewModel.cs

@ -26,137 +26,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
// timer1s.Start();
}
void Tick_Main_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S
{
DATA_view();
}
public string sys_machine; //显示log
public string Sys_machine //通知UI控件参数改变
{
get { return sys_machine; }
set { sys_machine = value; OnPropertyChanged("Sys_machine"); }
}
public static bool TechnologicalProcess_bool = true;
private async void DATA_view()//IO显示
{
await Task.Run(() =>
{
try
{
TechnologicalMachine_View = ToObservableCollection<TechnologicalM>(Machines);
}
catch (Exception) { }
try
{
if (dt_TP.Rows.Count >= 0)
{
if (TechnologicalProcess_bool) TechnologicalProcess_View = ToObservableCollection<TechnologicalP>(dt_TP);
Sys_machine = MachineLOG;
}
}
catch (Exception) { }
});
}
ObservableCollection<TechnologicalP> technologicalProcess_View = new ObservableCollection<TechnologicalP>();
ObservableCollection<TechnologicalM> technologicalMachine_View = new ObservableCollection<TechnologicalM>();
public ObservableCollection<TechnologicalP> TechnologicalProcess_View
{
get { return technologicalProcess_View; }
set
{
technologicalProcess_View = value;
RaisePropertyChanged("TechnologicalProcess_View");
}
}
public ObservableCollection<TechnologicalM> TechnologicalMachine_View
{
get { return technologicalMachine_View; }
set
{
technologicalMachine_View = value;
RaisePropertyChanged("TechnologicalMachine_View");
}
}
public class TechnologicalM
{
public string Name { get; set; }
public string WorkOrder { get; set; }
public string Dyelot { get; set; }
public string Temperature { get; set; }
public string WaterLevel { get; set; }
public string Process { get; set; }
public string Step { get; set; }
public string Message { get; set; }
public string State { get; set; }
}
public class TechnologicalP
{
public string ProgramID { get; set; }
public string Program { get; set; }
public double Step { get; set; }
public string StepID { get; set; }
public string StepName { get; set; }
public string ParameterName { get; set; }
public string Parameter1 { get; set; }
public string Parameter2 { get; set; }
public string Parameter3 { get; set; }
public string Parameter4 { get; set; }
public string Parameter5 { get; set; }
public string DYELOT { get; set; }
}
public ObservableCollection<T> ToObservableCollection<T>(DataTable dt) where T : class, new()
{
Type t = typeof(T);
PropertyInfo[] propertys = t.GetProperties();
ObservableCollection<T> lst = new ObservableCollection<T>();
string typeName = string.Empty;
foreach (DataRow dr in dt.Rows)
{
T entity = new T();
foreach (PropertyInfo pi in propertys)
{
typeName = pi.Name;
if (dt.Columns.Contains(typeName))
{
if (!pi.CanWrite) continue;
object value = dr[typeName];
if (value == DBNull.Value) continue;
if (pi.PropertyType == typeof(string))
{
pi.SetValue(entity, value.ToString(), null);
}
else if (pi.PropertyType == typeof(int) || pi.PropertyType == typeof(int?))
{
pi.SetValue(entity, int.Parse(value.ToString()), null);
}
else if (pi.PropertyType == typeof(DateTime?) || pi.PropertyType == typeof(DateTime))
{
pi.SetValue(entity, DateTime.Parse(value.ToString()), null);
}
else if (pi.PropertyType == typeof(float))
{
pi.SetValue(entity, float.Parse(value.ToString()), null);
}
else if (pi.PropertyType == typeof(double))
{
pi.SetValue(entity, double.Parse(value.ToString()), null);
}
else
{
pi.SetValue(entity, value, null);
}
}
}
lst.Add(entity);
}
return lst;
}
}
}

Loading…
Cancel
Save