|
|
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 RealtimeWarningViewModule : ViewModelBase
|
|
|
{
|
|
|
#region base parameters
|
|
|
private int rows = 100;
|
|
|
private int pagenumber = 1;
|
|
|
public RealtimeWarningView View { get; set; }
|
|
|
private bool IsConfirm;
|
|
|
private bool isLoading;
|
|
|
private AppEnum.PathType _CurrentPathType;
|
|
|
public AppEnum.PathType CurrentPathType
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _CurrentPathType;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_CurrentPathType = value;
|
|
|
OnPropertyChanged("CurrentPathType");
|
|
|
}
|
|
|
}
|
|
|
private System.Timers.Timer timer;
|
|
|
private bool forceRefresh = false;
|
|
|
#endregion
|
|
|
|
|
|
#region constructor
|
|
|
public RealtimeWarningViewModule()
|
|
|
{
|
|
|
View = new RealtimeWarningView();
|
|
|
View.DataContext = this;
|
|
|
|
|
|
InitializeCommands();
|
|
|
InitializeParameters();
|
|
|
}
|
|
|
|
|
|
private void InitializeCommands()
|
|
|
{
|
|
|
ConfirmAlamCommand = new DelegateCommand(OnConfirmAlamCommand);
|
|
|
}
|
|
|
|
|
|
public override void InitializeParameters(object content = null)
|
|
|
{
|
|
|
IsConfirm = false;
|
|
|
WindowTitle = "";
|
|
|
SysRealtimeWarnings = new ObservableCollection<SysWarningEntity>();
|
|
|
PagerControlViewer = new PagerControlViewModule();
|
|
|
PagerControlViewer.OnPager += new PagerControlViewModule.PagerHandler(PagerControlView_OnPager);
|
|
|
|
|
|
var thread = new Thread(new ParameterizedThreadStart(StartLoadTestItem)) { IsBackground = true };
|
|
|
thread.Start();
|
|
|
|
|
|
if (timer == null)
|
|
|
{
|
|
|
timer = new System.Timers.Timer();
|
|
|
timer.Interval = 1000;
|
|
|
timer.Elapsed += timer_Elapsed;
|
|
|
}
|
|
|
timer.Start();
|
|
|
}
|
|
|
|
|
|
~RealtimeWarningViewModule()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
public void ForceRefresh()
|
|
|
{
|
|
|
forceRefresh = true;
|
|
|
}
|
|
|
#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<SysWarningEntity> _SysRealtimeWarnings;
|
|
|
public ObservableCollection<SysWarningEntity> SysRealtimeWarnings
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _SysRealtimeWarnings;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_SysRealtimeWarnings = value;
|
|
|
OnPropertyChanged("SysRealtimeWarnings");
|
|
|
}
|
|
|
}
|
|
|
private PagerControlViewModule _PagerControlViewer;
|
|
|
public PagerControlViewModule PagerControlViewer
|
|
|
{
|
|
|
get { return _PagerControlViewer; }
|
|
|
set
|
|
|
{
|
|
|
_PagerControlViewer = value;
|
|
|
OnPropertyChanged("PagerControlViewer");
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region Binding Commands
|
|
|
private ICommand _ConfirmAlamCommand;
|
|
|
public ICommand ConfirmAlamCommand
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _ConfirmAlamCommand;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_ConfirmAlamCommand = value;
|
|
|
OnPropertyChanged("ConfirmAlamCommand");
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region Private Methods
|
|
|
private void PagerControlView_OnPager(int currentpagenumber, int currentrows)
|
|
|
{
|
|
|
pagenumber = currentpagenumber;
|
|
|
rows = currentrows;
|
|
|
|
|
|
if (!isLoading)
|
|
|
{
|
|
|
Thread t = new Thread(StartLoadTestItem);
|
|
|
t.IsBackground = true;
|
|
|
t.Start();
|
|
|
}
|
|
|
}
|
|
|
private void StartLoadTestItem(object key)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
isLoading = true;
|
|
|
|
|
|
List<string> ids = SysRealtimeWarnings.Select(q => q.RecId).ToList();
|
|
|
var record = SysWarningDA.Load(new PagerEntity() { PageIndex = pagenumber, Rows = rows, Conditions = " and createtime > date('now') and EndTime is null " });
|
|
|
List<SysWarningEntity> logs = (List<SysWarningEntity>)record.rows;
|
|
|
if (logs.Any(q => !ids.Contains(q.RecId)) || logs?.Count != SysRealtimeWarnings?.Count || forceRefresh)
|
|
|
{
|
|
|
forceRefresh = false;
|
|
|
View.Dispatcher.Invoke((Action)(() =>
|
|
|
{
|
|
|
SysRealtimeWarnings.Clear();
|
|
|
foreach (var s in logs)
|
|
|
{
|
|
|
SysRealtimeWarnings.Add(s);
|
|
|
}
|
|
|
OnPropertyChanged("HartLog");
|
|
|
TotalRecords = string.Format("<22><><EFBFBD>ü<EFBFBD>¼<EFBFBD><C2BC>: {0}", record.records);//.ToString("D5"));
|
|
|
PagerControlViewer.SetPager(rows, record.page, record.total, record.Count, record.records);
|
|
|
isLoading = false;
|
|
|
}));
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogService.WriteErrorLog(ex);
|
|
|
ShowErrorBox("Error:" + ex.Message);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
|
|
{
|
|
|
if (this.IsActivePage)
|
|
|
{
|
|
|
var thread = new Thread(new ParameterizedThreadStart(StartLoadTestItem)) { IsBackground = true };
|
|
|
thread.Start();
|
|
|
}
|
|
|
}
|
|
|
private void OnConfirmAlamCommand(Object sender)
|
|
|
{
|
|
|
SysRealtimeWarnings.Clear();
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ
|
|
|
foreach (var station in Global.Stations)
|
|
|
{
|
|
|
Global.ClearPauseState(station?.StationCode);
|
|
|
Global.ClearAbortState(station?.StationCode);
|
|
|
Global.ClearErrorState(station.StationCode);//<2F><><EFBFBD>ճ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ɫ<EFBFBD>澯
|
|
|
}
|
|
|
OutPort.SetBeepIO(false);
|
|
|
if (Global.RobotSpaceError)
|
|
|
{
|
|
|
Thread tr = new Thread(new ThreadStart((Action)(() =>
|
|
|
{
|
|
|
Robot.ClearError();
|
|
|
Global.RobotSpaceError = false;
|
|
|
})));
|
|
|
tr.IsBackground = true;
|
|
|
tr.Start();
|
|
|
Global.RobotWaitHome = false;
|
|
|
}
|
|
|
if (Global.RobotWaitError)
|
|
|
{
|
|
|
Thread tr = new Thread(new ThreadStart((Action)(() =>
|
|
|
{
|
|
|
Global.RobotWaitError = false;
|
|
|
Robot.Initialize();
|
|
|
})));
|
|
|
tr.IsBackground = true;
|
|
|
tr.Start();
|
|
|
Global.RobotWaitHome = false;
|
|
|
}
|
|
|
//ECAT<41><54><EFBFBD><EFBFBD>
|
|
|
string warningKey = "SYS_100";
|
|
|
if (SysWarningDA.WarningPool.ContainsKey(warningKey))
|
|
|
{
|
|
|
ShowProgressView("<22><>ʼ<EFBFBD><CABC><EFBFBD>³<EFBFBD>ʼ<EFBFBD><CABC>ECAT...");
|
|
|
SysWarningDA.WarningPool.Remove(warningKey);
|
|
|
string recid = SysWarningDA.LoadLastWarning(warningKey);
|
|
|
if (!string.IsNullOrWhiteSpace(recid))
|
|
|
{
|
|
|
SysWarningDA.RefreshEndTime(recid);
|
|
|
}
|
|
|
Thread tr = new Thread(new ThreadStart((Action)(() =>
|
|
|
{
|
|
|
DeviceControl.OpenCard();
|
|
|
DeviceControl.FindSlave();
|
|
|
HardPortsEntity port = OutPort.GetLightIO();
|
|
|
if (port != null)
|
|
|
{
|
|
|
//Ĭ<>ϵ<EFBFBD><CFB5><EFBFBD>
|
|
|
ControlCheck.PMCInvoke(false, "SetPortStatus", null, () => DeviceControl.SetPortStatus(port.NodeId, port.SlotId, port.PortIndex, 1));
|
|
|
}
|
|
|
OutPort.SetYellowIO(true);
|
|
|
CloseProgressView();
|
|
|
})));
|
|
|
tr.IsBackground = true;
|
|
|
tr.Start();
|
|
|
}
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>쳣<EFBFBD>澯
|
|
|
for (int i = 0; i < Global.Axises.Count; i++)
|
|
|
{
|
|
|
var axis = Global.Axises[i];
|
|
|
if (ExecuteHelper.CheckAxisWarning(axis.NodeId, axis.SlotId))
|
|
|
{
|
|
|
DeviceControl.ResetRalm(axis.NodeId, axis.SlotId);
|
|
|
}
|
|
|
}
|
|
|
OutPort.SetBeepIO(false);
|
|
|
Global.IsAlarming = false;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
Global.IsException = false;
|
|
|
Global.IsAlarmingConfirmed = true;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
SysWarningDA.RefreshAllEndTime();//<2F>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD>״̬
|
|
|
SysWarningDA.RefreshAlarming();//ˢ<>¸澯״̬
|
|
|
PortTimer.ClearWarningPool();
|
|
|
DTPTimer.ClearWarningPool();
|
|
|
GlobalTimer.ClearWarningPool();
|
|
|
HPTimer.ClearWarningPool();
|
|
|
YeweiTimer.ClearWarningPool();
|
|
|
ExecuteHelper.ClearWarningPool();
|
|
|
ExecuteRobotHelper.ClearWarningPool();
|
|
|
Global.RobotWaitError = false;
|
|
|
Global.Rs484WaitError = false;
|
|
|
Global.DTMWaitError = false;
|
|
|
var thread = new Thread(new ParameterizedThreadStart(StartLoadTestItem)) { IsBackground = true };
|
|
|
thread.Start();
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
}
|