Browse Source

修改信息页面MonitorView的显示逻辑,添加步骤表选择和右键的限制

master
sc 6 months ago
parent
commit
0345229416
  1. 27
      ConvertMoels/BoolToVisidilityConvert.cs
  2. 2
      SunlightCentralizedControlManagement_SCCM_.csproj
  3. 8
      View/MonitorView.xaml
  4. 186
      View/MonitorView.xaml.cs
  5. 24
      ViewModel/MainWindowViewModel.cs
  6. 162
      ViewModel/MonitorViewModel.cs

27
ConvertMoels/BoolToVisidilityConvert.cs

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
namespace SunlightCentralizedControlManagement_SCCM_.ConvertMoels
{
internal class BoolToVisidilityConvert : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return (value is bool boolvalue && boolvalue) ?
Visibility.Visible:
Visibility.Collapsed;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

2
SunlightCentralizedControlManagement_SCCM_.csproj

@ -102,6 +102,7 @@
</ApplicationDefinition> </ApplicationDefinition>
<Compile Include="ConvertMoels\BoolRBConvert.cs" /> <Compile Include="ConvertMoels\BoolRBConvert.cs" />
<Compile Include="ConvertMoels\StatenClassConvert.cs" /> <Compile Include="ConvertMoels\StatenClassConvert.cs" />
<Compile Include="ConvertMoels\BoolToVisidilityConvert.cs" />
<Compile Include="EX\DispenseState.xaml.cs"> <Compile Include="EX\DispenseState.xaml.cs">
<DependentUpon>DispenseState.xaml</DependentUpon> <DependentUpon>DispenseState.xaml</DependentUpon>
</Compile> </Compile>
@ -140,6 +141,7 @@
<Compile Include="ViewModel\CurveTempModel.cs" /> <Compile Include="ViewModel\CurveTempModel.cs" />
<Compile Include="ViewModel\CurveDiagramViewModel.cs" /> <Compile Include="ViewModel\CurveDiagramViewModel.cs" />
<Compile Include="ViewModel\MainWindowViewModel.cs" /> <Compile Include="ViewModel\MainWindowViewModel.cs" />
<Compile Include="ViewModel\MonitorViewModel.cs" />
<Compile Include="ViewModel\ManualDyelotModel.cs" /> <Compile Include="ViewModel\ManualDyelotModel.cs" />
<Compile Include="ViewModel\ViewModelLocator.cs" /> <Compile Include="ViewModel\ViewModelLocator.cs" />
<Compile Include="View\CurveTemp.xaml.cs"> <Compile Include="View\CurveTemp.xaml.cs">

8
View/MonitorView.xaml

@ -9,11 +9,12 @@
xmlns:rdp="clr-namespace:VncSharpWpf;assembly=VncSharpWpf" xmlns:rdp="clr-namespace:VncSharpWpf;assembly=VncSharpWpf"
xmlns:viewmodel="clr-namespace:SunlightCentralizedControlManagement_SCCM_.ViewModel" xmlns:viewmodel="clr-namespace:SunlightCentralizedControlManagement_SCCM_.ViewModel"
xmlns:ConvertMoels="clr-namespace:SunlightCentralizedControlManagement_SCCM_.ConvertMoels" xmlns:ConvertMoels="clr-namespace:SunlightCentralizedControlManagement_SCCM_.ConvertMoels"
d:DataContext="{d:DesignInstance Type=viewmodel:MainWindowViewModel}" d:DataContext="{d:DesignInstance Type=local:MonitorView}"
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="1000" d:DesignWidth="1900"> d:DesignHeight="1000" d:DesignWidth="1900">
<UserControl.Resources> <UserControl.Resources>
<ConvertMoels:StateToColorConvert x:Key="StateToColorConvert"/> <ConvertMoels:StateToColorConvert x:Key="StateToColorConvert"/>
<ConvertMoels:BoolToVisidilityConvert x:Key="BoolToVisidilityConvert"/>
</UserControl.Resources> </UserControl.Resources>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
@ -91,7 +92,7 @@
</DataGrid.Columns> </DataGrid.Columns>
</DataGrid> </DataGrid>
<GridSplitter Grid.Row="1" Height="5" HorizontalAlignment="Stretch" Background="#FF00204E"/> <GridSplitter Grid.Row="1" Height="5" HorizontalAlignment="Stretch" Background="#FF00204E"/>
<Grid Grid.Row="2" d:DataContext="{d:DesignInstance Type=viewmodel:MainWindowViewModel}"> <Grid Grid.Row="2" >
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition/> <ColumnDefinition/>
<ColumnDefinition Width="5"/> <ColumnDefinition Width="5"/>
@ -103,9 +104,10 @@
HorizontalGridLinesBrush="#FFC9C9C9" VerticalGridLinesBrush="#FFC9C9C9" Background="White" HorizontalGridLinesBrush="#FFC9C9C9" VerticalGridLinesBrush="#FFC9C9C9" Background="White"
GridLinesVisibility="All" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" BorderBrush="{x:Null}" GridLinesVisibility="All" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" BorderBrush="{x:Null}"
CanUserReorderColumns="False" CanUserSortColumns="False" CanUserResizeRows="False" CanUserResizeColumns="False" CanUserReorderColumns="False" CanUserSortColumns="False" CanUserResizeRows="False" CanUserResizeColumns="False"
CanUserDeleteRows="False" SelectionMode="Single" FontSize="15" Focusable="True" > CanUserDeleteRows="False" SelectionMode="Single" FontSize="15" Focusable="True" ContextMenuOpening="Gridstep_ContextMenuOpening">
<DataGrid.RowStyle> <DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}"> <Style TargetType="{x:Type DataGridRow}">
<Setter Property="IsHitTestVisible" Value="{Binding DataContext.IsInteractive,RelativeSource={RelativeSource AncestorType=DataGrid}}"/>
<Setter Property="Height" Value="30" /> <Setter Property="Height" Value="30" />
<Setter Property="FontSize" Value="25" /> <Setter Property="FontSize" Value="25" />
<Style.Triggers> <Style.Triggers>

186
View/MonitorView.xaml.cs

@ -33,20 +33,39 @@ using System.Net.NetworkInformation;
namespace SunlightCentralizedControlManagement_SCCM_.View namespace SunlightCentralizedControlManagement_SCCM_.View
{ {
/// <summary> /// <summary>
/// MonitorView.xaml 的交互逻辑 /// MonitorView.xaml 的交互逻辑
/// </summary> /// </summary>
public partial class MonitorView : UserControl public partial class MonitorView : 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 MonitorView() public MonitorView()
{ {
//DataContext = new MainWindowViewModel(); DataContext = this;
InitializeComponent(); InitializeComponent();
CountDown(); CountDown();
machine= MainWindowViewModel.machine; machine= MainWindowViewModel.machine;
workOrder= MainWindowViewModel.workOrder; workOrder= MainWindowViewModel.workOrder;
dyelot= MainWindowViewModel.dyelot; dyelot= MainWindowViewModel.dyelot;
machin_LOG.Text = MainWindowViewModel.machin_LOG; machin_LOG.Text = MainWindowViewModel.machin_LOG;
IsInteractive = false;
} }
private string machine; private string machine;
@ -69,7 +88,9 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
Curve.IsEnabled = true; Curve.IsEnabled = true;
Screen.IsEnabled = true; Screen.IsEnabled = true;
Receipt.IsEnabled = true; Receipt.IsEnabled = true;
MainWindowViewModel.TechnologicalProcess_bool = true; TechnologicalProcess_bool = true;
IsInteractive = false;
int rownum = Griddata.SelectedIndex;//获取鼠标选中行并定义变量 int rownum = Griddata.SelectedIndex;//获取鼠标选中行并定义变量
if (rownum != -1)//判断鼠标定位是否有效 if (rownum != -1)//判断鼠标定位是否有效
{ {
@ -87,7 +108,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
private void Gridstep_SelectionChanged(object sender, SelectionChangedEventArgs e) private void Gridstep_SelectionChanged(object sender, SelectionChangedEventArgs e)
{ {
MainWindowViewModel.TechnologicalProcess_bool = false; TechnologicalProcess_bool = false;
int rownum = Gridstep.SelectedIndex;//获取鼠标选中行并定义变量 int rownum = Gridstep.SelectedIndex;//获取鼠标选中行并定义变量
if (rownum != -1)//判断鼠标定位是否有效 if (rownum != -1)//判断鼠标定位是否有效
{ {
@ -191,6 +212,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
}//曲线 }//曲线
private void ListViewItem_Resume(object sender, MouseButtonEventArgs e) private void ListViewItem_Resume(object sender, MouseButtonEventArgs e)
{ {
IsInteractive = false;
if (!string.IsNullOrEmpty(machine)) if (!string.IsNullOrEmpty(machine))
{ {
Dictionary<string, object> dat_821 = new Dictionary<string, object>(); Dictionary<string, object> dat_821 = new Dictionary<string, object>();
@ -209,10 +231,11 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
Resume.IsEnabled = false; Resume.IsEnabled = false;
Delete.IsEnabled = false; Delete.IsEnabled = false;
Jump.IsEnabled = false; Jump.IsEnabled = false;
MainWindowViewModel.TechnologicalProcess_bool = true; TechnologicalProcess_bool = true;
}//恢复 }//恢复
private void ListViewItem_Paused(object sender, MouseButtonEventArgs e) private void ListViewItem_Paused(object sender, MouseButtonEventArgs e)
{ {
IsInteractive = true;
if (!string.IsNullOrEmpty(machine)) if (!string.IsNullOrEmpty(machine))
{ {
Dictionary<string, object> dat_821 = new Dictionary<string, object>(); Dictionary<string, object> dat_821 = new Dictionary<string, object>();
@ -236,6 +259,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
}//暂停 }//暂停
private void ListViewItem_Stop(object sender, MouseButtonEventArgs e) private void ListViewItem_Stop(object sender, MouseButtonEventArgs e)
{ {
IsInteractive = false;
if (!string.IsNullOrEmpty(machine)) if (!string.IsNullOrEmpty(machine))
{ {
Dictionary<string, object> dat_821 = new Dictionary<string, object>(); Dictionary<string, object> dat_821 = new Dictionary<string, object>();
@ -282,7 +306,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
DAT = "SC821" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", "ID='" + index + "'") + dat_821.ToJsonString() DAT = "SC821" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", "ID='" + index + "'") + dat_821.ToJsonString()
}); });
MainWindowViewModel.TechnologicalProcess_bool = true; TechnologicalProcess_bool = true;
} }
private void ListViewItem_Jump(object sender, MouseButtonEventArgs e) private void ListViewItem_Jump(object sender, MouseButtonEventArgs e)
@ -306,7 +330,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
DAT = "SC821" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", "ID='" + index + "'") + dat_821.ToJsonString() DAT = "SC821" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", "ID='" + index + "'") + dat_821.ToJsonString()
}); });
MainWindowViewModel.TechnologicalProcess_bool = true; TechnologicalProcess_bool = true;
}//跳步 }//跳步
private void ListViewItem_Insert(object sender, MouseButtonEventArgs e) private void ListViewItem_Insert(object sender, MouseButtonEventArgs e)
{ {
@ -317,7 +341,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
}//插入 }//插入
private void Insert_ButtonClicked(object sender, AddressUpdateEventArgs e)//cr返回结果 private void Insert_ButtonClicked(object sender, AddressUpdateEventArgs e)//cr返回结果
{ {
MainWindowViewModel.TechnologicalProcess_bool = true; TechnologicalProcess_bool = true;
Dictionary<string, object> dat_821 = new Dictionary<string, object>(); Dictionary<string, object> dat_821 = new Dictionary<string, object>();
dat_821.Clear(); dat_821.Clear();
dat_821.Add("INSTRUCTION", "INSERT"); dat_821.Add("INSTRUCTION", "INSERT");
@ -355,7 +379,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
DAT = "SC821" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", "ID='" + index + "'") + dat_821.ToJsonString() DAT = "SC821" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", "ID='" + index + "'") + dat_821.ToJsonString()
}); });
MainWindowViewModel.TechnologicalProcess_bool = true; TechnologicalProcess_bool = true;
} }
}//删除 }//删除
string Numder = null; string Numder = null;
@ -414,7 +438,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
DAT = "SC821" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", "ID='" + index + "'") + dat_821.ToJsonString() DAT = "SC821" + MainWindowViewModel.Selet_Machines(MainWindowViewModel.Machines, "SYSKEY", "ID='" + index + "'") + dat_821.ToJsonString()
}); });
MainWindowViewModel.TechnologicalProcess_bool = true; TechnologicalProcess_bool = true;
} }
} }
} }
@ -431,6 +455,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
int Time_D = 0; int Time_D = 0;
void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S
{ {
DATA_view();
if (Paused.IsEnabled) if (Paused.IsEnabled)
{ {
if (!Resume.IsEnabled) if (!Resume.IsEnabled)
@ -438,7 +463,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
Time_D++; Time_D++;
if (Time_D > 10) if (Time_D > 10)
{ {
MainWindowViewModel.TechnologicalProcess_bool = true; TechnologicalProcess_bool = true;
} }
} }
} }
@ -497,7 +522,146 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
} }
} }
public string sys_machine; //显示log
public string Sys_machine //通知UI控件参数改变
{
get { return sys_machine; }
set { sys_machine = value; OnPropertyChanged("Sys_machine"); }
}
bool _isInteractive;
public bool IsInteractive//步骤表交互选择
{
get => _isInteractive;
set
{
_isInteractive = value;
OnPropertyChanged("IsInteractive");
}
}
private void Gridstep_ContextMenuOpening(object sender, ContextMenuEventArgs e)
{
if(!IsInteractive) e.Handled = true;//阻止菜单显示
}
public static bool TechnologicalProcess_bool = true;
private async void DATA_view()//IO显示
{
await Task.Run(() =>
{
try
{
TechnologicalMachine_View = ToObservableCollection<TechnologicalM>(MainWindowViewModel.Machines);
}
catch (Exception) { }
try
{
if (MainWindowViewModel.dt_TP.Rows.Count >= 0)
{
if (TechnologicalProcess_bool) TechnologicalProcess_View = ToObservableCollection<TechnologicalP>(MainWindowViewModel.dt_TP);
Sys_machine = MainWindowViewModel.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;
}
} }
} }

24
ViewModel/MainWindowViewModel.cs

@ -331,12 +331,12 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
set { sys_Time = value; OnPropertyChanged("Sys_Time"); } set { sys_Time = value; OnPropertyChanged("Sys_Time"); }
} }
public static string MachineLOG; public static string MachineLOG;
public string sys_machine; //显示log /* public string sys_machine; //显示log
public string Sys_machine //通知UI控件参数改变 public string Sys_machine //通知UI控件参数改变
{ {
get { return sys_machine; } get { return sys_machine; }
set { sys_machine = value; OnPropertyChanged("Sys_machine"); } set { sys_machine = value; OnPropertyChanged("Sys_machine"); }
} }*/
public static object Selet_Machines(DataTable DB, string name, string key)//查询 public static object Selet_Machines(DataTable DB, string name, string key)//查询
{ {
@ -422,11 +422,11 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
} }
} }
catch (Exception) { } catch (Exception) { }
try /* try
{ {
TechnologicalMachine_View = ToObservableCollection<TechnologicalM>(Machines); TechnologicalMachine_View = ToObservableCollection<TechnologicalM>(Machines);
} }
catch (Exception) { } catch (Exception) { }*/
try try
{ {
if (dt_ParameterSet.Rows.Count >= 0) if (dt_ParameterSet.Rows.Count >= 0)
@ -443,7 +443,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
} }
} }
catch (Exception) { } catch (Exception) { }
try /* try
{ {
if (dt_TP.Rows.Count >= 0) if (dt_TP.Rows.Count >= 0)
{ {
@ -451,7 +451,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
Sys_machine = MachineLOG; Sys_machine = MachineLOG;
} }
} }
catch (Exception) { } catch (Exception) { }*/
}); });
} }
@ -460,8 +460,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
ObservableCollection<DATA_M> sysData_M = new ObservableCollection<DATA_M>(); ObservableCollection<DATA_M> sysData_M = new ObservableCollection<DATA_M>();
ObservableCollection<ParameterSet> paramete_Set = new ObservableCollection<ParameterSet>(); ObservableCollection<ParameterSet> paramete_Set = new ObservableCollection<ParameterSet>();
ObservableCollection<SysSet> sys_Set = new ObservableCollection<SysSet>(); ObservableCollection<SysSet> sys_Set = new ObservableCollection<SysSet>();
ObservableCollection<TechnologicalP> technologicalProcess_View = new ObservableCollection<TechnologicalP>(); //ObservableCollection<TechnologicalP> technologicalProcess_View = new ObservableCollection<TechnologicalP>();
ObservableCollection<TechnologicalM> technologicalMachine_View = new ObservableCollection<TechnologicalM>(); //ObservableCollection<TechnologicalM> technologicalMachine_View = new ObservableCollection<TechnologicalM>();
public ObservableCollection<DATA_A> SYSData_A public ObservableCollection<DATA_A> SYSData_A
{ {
@ -491,7 +491,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
RaisePropertyChanged("SYSData_M"); RaisePropertyChanged("SYSData_M");
} }
} }
public ObservableCollection<TechnologicalP> TechnologicalProcess_View /* public ObservableCollection<TechnologicalP> TechnologicalProcess_View
{ {
get { return technologicalProcess_View; } get { return technologicalProcess_View; }
set set
@ -508,7 +508,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
technologicalMachine_View = value; technologicalMachine_View = value;
RaisePropertyChanged("TechnologicalMachine_View"); RaisePropertyChanged("TechnologicalMachine_View");
} }
} }*/
public ObservableCollection<ParameterSet> Paramete_Set public ObservableCollection<ParameterSet> Paramete_Set
{ {
get { return paramete_Set; } get { return paramete_Set; }
@ -551,7 +551,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
public string PLC { get; set; } public string PLC { get; set; }
public string type { get; set; } public string type { get; set; }
} }
public class TechnologicalM /* public class TechnologicalM
{ {
public string Name { get; set; } public string Name { get; set; }
public string WorkOrder { get; set; } public string WorkOrder { get; set; }
@ -578,7 +578,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
public string Parameter4 { get; set; } public string Parameter4 { get; set; }
public string Parameter5 { get; set; } public string Parameter5 { get; set; }
public string DYELOT { get; set; } public string DYELOT { get; set; }
} }*/
public class ParameterSet public class ParameterSet
{ public string Category { get; set; } { public string Category { get; set; }
public string ParameterID { get; set; } public string ParameterID { get; set; }

162
ViewModel/MonitorViewModel.cs

@ -0,0 +1,162 @@
using SunlightCentralizedControlManagement_SCCM_.EX;
using SunlightCentralizedControlManagement_SCCM_.UserClass;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Threading;
using static SunlightCentralizedControlManagement_SCCM_.ViewModel.MainWindowViewModel;
namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
public class MonitorViewModel : ViewModelBase
{
public MonitorViewModel()
{
// DispatcherTimer timer1s = new DispatcherTimer(DispatcherPriority.Normal);//初始化循环,每1秒调用一次Tick
// timer1s.Interval = TimeSpan.FromMilliseconds(950);//秒
// timer1s.Tick += Tick_Main_1S;
// 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