|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|