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 IOViewModule : ViewModelBase { #region base parameters private int rows = 20; private int pagenumber = 1; public IOView View { get; set; } private bool IsConfirm; private bool isLoading; private System.Timers.Timer timer; #endregion #region constructor public IOViewModule() { View = new IOView(); View.DataContext = this; InitializeCommands(); InitializeParameters(); } private void InitializeCommands() { InputCommand = new DelegateCommand(OnInputCommand); OutputCommand = new DelegateCommand(OnOutputCommand); } public override void InitializeParameters(object content = null) { IsConfirm = false; WindowTitle = ""; } ~IOViewModule() { } public void LoadDefaultValue() { Ports = new ObservableCollection(); for (int i = 0; i < Global.InputIOs.Count; i++) { Ports.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 _Ports; public ObservableCollection Ports { get { return _Ports; } set { _Ports = value; OnPropertyChanged("Ports"); } } private ObservableCollection _PortViews; public ObservableCollection PortViews { get { return _PortViews; } set { _PortViews = value; OnPropertyChanged("PortViews"); } } #endregion #region Binding Commands private ICommand _InputCommand; public ICommand InputCommand { get { return _InputCommand; } set { _InputCommand = value; OnPropertyChanged("InputCommand"); } } private ICommand _OutputCommand; public ICommand OutputCommand { get { return _OutputCommand; } set { _OutputCommand = value; OnPropertyChanged("OutputCommand"); } } #endregion #region Private Methods private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { for (int i = 0; i < Ports.Count; i++) { var port = Global.InputIOs?.FirstOrDefault(q => q.PortCode == Ports[i].PortCode); if (port != null) { Ports[i].IsOpen = port.IsOpen; } port = Global.OutputIOs?.FirstOrDefault(q => q.PortCode == Ports[i].PortCode); if (port != null) { Ports[i].IsOpen = port.IsOpen; } } } private void OnInputCommand(Object sender) { Ports.Clear(); for (int i = 0; i < Global.InputIOs.Count; i++) { Ports.Add(Global.InputIOs[i]); } } private void OnOutputCommand(Object sender) { Ports.Clear(); for (int i = 0; i < Global.OutputIOs.Count; i++) { Ports.Add(Global.OutputIOs[i]); } } #endregion } }