You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
5.6 KiB

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using GummingCommon;
using GummingEntity;
using GummingSupport;
using GummingControl;
using System.Text;
using GummingBusiness;
using Newtonsoft.Json;
using GummingLine;
namespace Gumming
{
public class EnviromentViewModule : ViewModelBase
{
#region base parameters
private int rows = 20;
private int pagenumber = 1;
public EnviromentView View { get; set; }
private bool IsConfirm;
private bool isLoading;
private System.Timers.Timer timer;
#endregion
#region constructor
public EnviromentViewModule()
{
View = new EnviromentView();
View.DataContext = this;
InitializeCommands();
InitializeParameters();
}
private void InitializeCommands()
{
}
public override void InitializeParameters(object content = null)
{
IsConfirm = false;
WindowTitle = "";
}
~EnviromentViewModule()
{
}
public void LoadDefaultValue()
{
Ports2 = new ObservableCollection<HardPortsEntity>();
Ports3 = new ObservableCollection<HardPortsEntity>();
Ports4 = new ObservableCollection<HardPortsEntity>();
Ports5 = new ObservableCollection<HardPortsEntity>();
for (int i = 0; i < Global.InputIOs.Count; i++)
{
var port = Global.InputIOs[i];
if (port.PortType == 2)
{
Ports2.Add(Global.InputIOs[i]);
}
else if (port.PortType == 3)
{
Ports3.Add(Global.InputIOs[i]);
}
else if (port.PortType == 4)
{
Ports4.Add(Global.InputIOs[i]);
}
else if (port.PortType == 5)
{
Ports5.Add(Global.InputIOs[i]);
}
}
if (timer == null)
{
timer = new System.Timers.Timer();
timer.Interval = 5000;
timer.Elapsed += timer_Elapsed;
timer.Start();
}
}
#endregion
#region Binding Properties
public string WindowTitle { get; private set; }
private string _TotalRecords;
public string TotalRecords
{
get
{
return _TotalRecords;
}
set
{
_TotalRecords = value;
OnPropertyChanged("TotalRecords");
}
}
private ObservableCollection<HardPortsEntity> _Ports2;
public ObservableCollection<HardPortsEntity> Ports2
{
get
{
return _Ports2;
}
set
{
_Ports2 = value;
OnPropertyChanged("Ports2");
}
}
private ObservableCollection<HardPortsEntity> _Ports3;
public ObservableCollection<HardPortsEntity> Ports3
{
get
{
return _Ports3;
}
set
{
_Ports3 = value;
OnPropertyChanged("Ports3");
}
}
private ObservableCollection<HardPortsEntity> _Ports4;
public ObservableCollection<HardPortsEntity> Ports4
{
get
{
return _Ports4;
}
set
{
_Ports4 = value;
OnPropertyChanged("Ports4");
}
}
private ObservableCollection<HardPortsEntity> _Ports5;
public ObservableCollection<HardPortsEntity> Ports5
{
get
{
return _Ports5;
}
set
{
_Ports5 = value;
OnPropertyChanged("Ports5");
}
}
#endregion
#region Binding Commands
#endregion
#region Private Methods
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
for (int i = 0; i < Ports2.Count; i++)
{
var port = Global.InputIOs?.FirstOrDefault(q => q.PortCode == Ports2[i].PortCode);
if (port != null)
{
Ports2[i].IsOpen = port.IsOpen;
}
}
for (int i = 0; i < Ports3.Count; i++)
{
var port = Global.InputIOs?.FirstOrDefault(q => q.PortCode == Ports3[i].PortCode);
if (port != null)
{
Ports3[i].IsOpen = port.IsOpen;
}
}
for (int i = 0; i < Ports4.Count; i++)
{
var port = Global.InputIOs?.FirstOrDefault(q => q.PortCode == Ports4[i].PortCode);
if (port != null)
{
Ports4[i].IsOpen = port.IsOpen;
}
}
for (int i = 0; i < Ports5.Count; i++)
{
var port = Global.InputIOs?.FirstOrDefault(q => q.PortCode == Ports5[i].PortCode);
if (port != null)
{
Ports5[i].IsOpen = port.IsOpen;
}
}
}
#endregion
}
}