This commit is contained in:
sc committed 2024-12-05 01:09:10 +08:00
commit 6e4c993835
3 files changed
+210 -15

No files matched your search

+162
View File
@@ -5,18 +5,22 @@ using SunlightCentralizedControlManagement_SCCM_.Properties;
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.Controls;
using System.Windows.Forms;
using System.Windows.Media;
using System.Windows.Threading;
using TouchSocket.Core;
using TouchSocket.Sockets;
using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper;
using static System.Net.WebRequestMethods;
namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
@@ -121,6 +125,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
void Tick_Event_5S(object sender, EventArgs e)//Tick_Event周期执行事件5S
{
for (int i = 0; i < Machinesdata_Count; i++)
{
if (Selet_Machines(Machines, "State", i).ToString() == "801")
@@ -132,6 +137,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
}
void DisTimer_500MS(object sender, EventArgs e)//Tick_Event周期执行事件500MS
{
DATA_view();
for (int i = 0; i < Machinesdata_Count; i++)
{
string mac_s = Selet_Machines(Machines, "State", i).ToString();
@@ -157,6 +164,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
CountDown();
TcpClientNEW();
SQL_LINK();
}
public static TcpClient[] MachiensTcpClient = new TcpClient[999];
@@ -224,5 +232,159 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
// LogGing.LogGingDATA("SDTD:" + ex.ToString());
}
}
public static DataTable dt_d = new DataTable("DIO");
public static DataTable dt_a = new DataTable("AIO");
public static DataTable dt_m = new DataTable("M");
public static DataTable dt_TP = new DataTable();
private async void DATA_view()//IO显示
{
await Task.Run(() =>
{
try
{
TechnologicalProcess_View = ToObservableCollection<Technological>(dt_TP);
}
catch (Exception) { }
});
}
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<Technological> technologicalProcess_View = new ObservableCollection<Technological>();
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<Technological> TechnologicalProcess_View
{
get { return technologicalProcess_View; }
set
{
technologicalProcess_View = value;
RaisePropertyChanged("TechnologicalProcess_View");
}
}
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 Technological
{
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 Parameter6 { get; set; }
public string Parameter7 { get; set; }
public string Parameter8 { get; set; }
public string Parameter9 { get; set; }
public string Parameter10 { 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;
}
}
}