using MaterialTraceability.Business;
using MaterialTraceability.Business.Impl;
using MaterialTraceability.Entity.DAO;
using MaterialTraceability.Entity.DTO;
using MaterialTraceability.Entity.Enum;
using MaterialTraceability.SqlSugar;
using MaterialTraceability.SqlSugar.ServiceImpl;
using MaterialTraceabilityUI.Common;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace MaterialTraceabilityUI
{
///
/// DieCuttingProcess.xaml 的交互逻辑
///
public partial class DieCuttingProcess : UserControl
{
private EquipBusiness equipBusiness = new EquipBusiness();
private IBaseServices logInfoServices = new BaseServices();
private IBaseServices shaftInfoServices = new BaseServices();
private int position = 0;
private PlcBusiness plcBusiness = new PlcBusiness();
private UpLoadBusiness loadBusiness = UpLoadBusiness.Instance;
private AppConfigDto appConfig = AppConfigDto.Instance;
public DieCuttingProcess()
{
InitializeComponent();
try
{
if (appConfig.processId.Contains("MQ"))
{
UserControlInit();
MainBusiness.LogRefreshEvent += LogRefresh;
MQSignalReadBusiness.LogRefreshEvent += LogRefresh;
MQSignalReadBusiness.ViewModelRefreshEvent += ProductionParam;
refreshThread();
}
}catch(Exception ex)
{
Console.WriteLine("界面异常:"+ex.Message);
Console.ReadLine();
}
}
public void ProductionParam(ViewModelDto viewModelDto)
{
if (viewModelDto.rfidInfo != null)
{
Action action;
switch (viewModelDto.rfidInfo.position)
{
case 6:
if(appConfig.machineId == 3)
{
action = () =>
{
this.SFC_1.Text = "SFC:" + viewModelDto.rfidInfo.sfc;
};
SFC_1.Dispatcher.BeginInvoke(action);
action = () =>
{
this.RFID_1.Text = "RFID:" + viewModelDto.rfidInfo.rfid;
};
RFID_1.Dispatcher.BeginInvoke(action);
action = () =>
{
this.EA_1.Text = "EA:" + viewModelDto.rfidInfo.ea;
};
EA_1.Dispatcher.BeginInvoke(action);
}
if(appConfig.machineId == 4)
{
action = () =>
{
this.SFC_2.Text = "SFC:" + viewModelDto.rfidInfo.sfc;
};
SFC_2.Dispatcher.BeginInvoke(action);
action = () =>
{
this.RFID_2.Text = "RFID:" + viewModelDto.rfidInfo.rfid;
};
RFID_2.Dispatcher.BeginInvoke(action);
action = () =>
{
this.EA_2.Text = "EA:" + viewModelDto.rfidInfo.ea;
};
EA_2.Dispatcher.BeginInvoke(action);
}
break;
case 5:
if(appConfig.machineId == 3)
{
action = () =>
{
this.SFC_2.Text = "SFC:" + viewModelDto.rfidInfo.sfc;
};
SFC_2.Dispatcher.BeginInvoke(action);
action = () =>
{
this.RFID_2.Text = "RFID:" + viewModelDto.rfidInfo.rfid;
};
RFID_2.Dispatcher.BeginInvoke(action);
action = () =>
{
this.EA_2.Text = "EA:" + viewModelDto.rfidInfo.ea;
};
EA_2.Dispatcher.BeginInvoke(action);
}
if(appConfig.machineId == 4)
{
action = () =>
{
this.SFC_1.Text = "SFC:" + viewModelDto.rfidInfo.sfc;
};
SFC_1.Dispatcher.BeginInvoke(action);
action = () =>
{
this.RFID_1.Text = "RFID:" + viewModelDto.rfidInfo.rfid;
};
RFID_1.Dispatcher.BeginInvoke(action);
action = () =>
{
this.EA_1.Text = "EA:" + viewModelDto.rfidInfo.ea;
};
EA_1.Dispatcher.BeginInvoke(action);
}
break;
case 3:
if(appConfig.machineId == 3)
{
action = () =>
{
this.SFC_3.Text = "SFC:" + viewModelDto.rfidInfo.sfc;
};
SFC_3.Dispatcher.BeginInvoke(action);
action = () =>
{
this.RFID_3.Text = "RFID:" + viewModelDto.rfidInfo.rfid;
};
RFID_3.Dispatcher.BeginInvoke(action);
action = () =>
{
this.EA_3.Text = "EA:" + viewModelDto.rfidInfo.ea;
};
EA_3.Dispatcher.BeginInvoke(action);
}
if(appConfig.machineId == 4)
{
action = () =>
{
this.SFC_4.Text = "SFC:" + viewModelDto.rfidInfo.sfc;
};
SFC_4.Dispatcher.BeginInvoke(action);
action = () =>
{
this.RFID_4.Text = "RFID:" + viewModelDto.rfidInfo.rfid;
};
RFID_4.Dispatcher.BeginInvoke(action);
action = () =>
{
this.EA_4.Text = "EA:" + viewModelDto.rfidInfo.ea;
};
EA_4.Dispatcher.BeginInvoke(action);
}
break;
case 1:
if(appConfig.machineId == 3)
{
action = () =>
{
this.SFC_4.Text = "SFC:" + viewModelDto.rfidInfo.sfc;
};
SFC_4.Dispatcher.BeginInvoke(action);
action = () =>
{
this.RFID_4.Text = "RFID:" + viewModelDto.rfidInfo.rfid;
};
RFID_4.Dispatcher.BeginInvoke(action);
action = () =>
{
this.EA_4.Text = "EA:" + viewModelDto.rfidInfo.ea;
};
EA_4.Dispatcher.BeginInvoke(action);
}
if (appConfig.machineId == 4)
{
action = () =>
{
this.SFC_3.Text = "SFC:" + viewModelDto.rfidInfo.sfc;
};
SFC_3.Dispatcher.BeginInvoke(action);
action = () =>
{
this.RFID_3.Text = "RFID:" + viewModelDto.rfidInfo.rfid;
};
RFID_3.Dispatcher.BeginInvoke(action);
action = () =>
{
this.EA_3.Text = "EA:" + viewModelDto.rfidInfo.ea;
};
EA_3.Dispatcher.BeginInvoke(action);
}
break;
case 4:
if(appConfig.machineId == 3)
{
action = () =>
{
this.SFC_5.Text = "SFC:" + viewModelDto.rfidInfo.sfc;
};
SFC_5.Dispatcher.BeginInvoke(action);
action = () =>
{
this.RFID_5.Text = "RFID:" + viewModelDto.rfidInfo.rfid;
};
RFID_5.Dispatcher.BeginInvoke(action);
action = () =>
{
this.EA_5.Text = "EA:" + viewModelDto.rfidInfo.ea;
};
EA_5.Dispatcher.BeginInvoke(action);
}
if(appConfig.machineId == 4)
{
action = () =>
{
this.SFC_6.Text = "SFC:" + viewModelDto.rfidInfo.sfc;
};
SFC_6.Dispatcher.BeginInvoke(action);
action = () =>
{
this.RFID_6.Text = "RFID:" + viewModelDto.rfidInfo.rfid;
};
RFID_6.Dispatcher.BeginInvoke(action);
action = () =>
{
this.EA_6.Text = "EA:" + viewModelDto.rfidInfo.ea;
};
EA_6.Dispatcher.BeginInvoke(action);
}
break;
case 2:
if (appConfig.machineId == 3)
{
action = () =>
{
this.SFC_6.Text = "SFC:" + viewModelDto.rfidInfo.sfc;
};
SFC_6.Dispatcher.BeginInvoke(action);
action = () =>
{
this.RFID_6.Text = "RFID:" + viewModelDto.rfidInfo.rfid;
};
RFID_6.Dispatcher.BeginInvoke(action);
action = () =>
{
this.EA_6.Text = "EA:" + viewModelDto.rfidInfo.ea;
};
EA_6.Dispatcher.BeginInvoke(action);
}
if (appConfig.machineId == 4)
{
action = () =>
{
this.SFC_5.Text = "SFC:" + viewModelDto.rfidInfo.sfc;
};
SFC_5.Dispatcher.BeginInvoke(action);
action = () =>
{
this.RFID_5.Text = "RFID:" + viewModelDto.rfidInfo.rfid;
};
RFID_5.Dispatcher.BeginInvoke(action);
action = () =>
{
this.EA_5.Text = "EA:" + viewModelDto.rfidInfo.ea;
};
EA_5.Dispatcher.BeginInvoke(action);
}
break;
default:
break;
}
}
}
private void refreshThread()
{
//Thread plcRead = new Thread(refreshTimer);
//plcRead.Start();
System.Timers.Timer timer = new System.Timers.Timer(1000 * 30);
timer.Elapsed += new System.Timers.ElapsedEventHandler(refreshEquipStatus);
timer.AutoReset = true;
timer.Enabled = true;
timer.Start();
}
private void refreshEquipStatus(object source, System.Timers.ElapsedEventArgs e)
{
equipBusiness.CheckEquipState(); //equipBusiness.CheckEquipState();
UpdataDeviceStatus();
}
public void LogRefresh(LogType logType, string massage)
{
string info = massage;
string logTypeStr = "";
int isAlarm = 0;
if (logType == LogType.MesLog)
{
logTypeStr = "MES";
ListBoxItemAdd(this.MesLog, massage);
}
if (logType == LogType.PlcLog)
{
logTypeStr = "PLC";
ListBoxItemAdd(this.PlcLog, massage);
}
if (logType == LogType.RfidLog)
{
logTypeStr = "RFID";
ListBoxItemAdd(this.RfidLog, massage);
}
if (logType == LogType.AlarmLog)
{
logTypeStr = "Alarm";
isAlarm = 1;
ListBoxItemAdd(this.AlarmLog, massage);
loadBusiness.SaveLogRecord(0, massage);
}
logInfoServices.Add(new RecordLogInfo()
{
id = System.Guid.NewGuid().ToString("N"),
processId = "LY_A",
machineId = ConfigurationManager.AppSettings["machineId"].ToString(),
alarmType = logTypeStr,
alarmInfo = info,
isAlarm = isAlarm,
recordTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
});
}
private List logInfos = new List();
///
/// ListBox刷新
///
///
///
private void ListBoxItemAdd(ListBox listBox, string massage)
{
LogHelperBusiness.ViewLog(massage);
logInfos.Add(new LogInfoItem()
{
listBox = listBox,
recordTime = DateTime.Now,
message = String.Format("{0} {1}", DateTime.Now.ToString("MM-dd HH:mm:ss"), massage)
});
while (logInfos.Count > 120)
{
logInfos.RemoveAt(0);
}
Action action;
action = () =>
{
listBox.Items.Clear();
var loginList = logInfos.ToArray();
var strArray = loginList.Where(x => x.listBox == listBox).OrderByDescending(x => x.recordTime).ToList();
if (strArray != null)
{
foreach (var str in strArray)
{
SplitByLen(str.message, 50).ForEach(x =>
{
listBox.Items.Add(x);
});
}
}
};
listBox.Dispatcher.BeginInvoke(action);
}
public static List SplitByLen(string str, int separatorCharNum)
{
string tempStr = str;
List strList = new List();
if (string.IsNullOrEmpty(str) || str.Length <= separatorCharNum)
{
strList.Add(str);
return strList;
}
int iMax = Convert.ToInt32(Math.Ceiling(str.Length / (separatorCharNum * 1.0)));
for (int i = 0; i < iMax; i++)
{
string currMsg = tempStr.Substring(0, tempStr.Length > separatorCharNum ? separatorCharNum : tempStr.Length);
strList.Add(currMsg);
if (tempStr.Length > separatorCharNum)
{
tempStr = tempStr.Substring(separatorCharNum, tempStr.Length - separatorCharNum);
}
}
return strList;
}
public void UserControlInit()
{
ListBoxItemAdd(this.RfidLog, "模切RFID物料追溯系统初始化");
//查询前五个小时的数据
DateTime beginTime = DateTime.Now.AddHours(-5);
Expression> exp = s1 => true;
exp = exp.And(x => x.processId == appConfig.processId && Convert.ToDateTime(x.bindTime) > beginTime);
List shaftInfos = shaftInfoServices.Query(exp).Result;
if (shaftInfos == null || shaftInfos.Count == 0)
{
ListBoxItemAdd(this.RfidLog, "程序初始化数据为空");
return;
}
shaftInfos.ForEach(x =>
{
ProductionParam(new ViewModelDto()
{
rfidInfo = new RfidInfoDto()
{
rfid = x.bindRfid,
sfc = x.bindSfc,
ea = x.bindEaValue,
position = Convert.ToInt32(x.positionId)
},
plcStatus = true,
});
});
}
private void UpdataDeviceStatus()
{
var equipStatus = equipBusiness.Equiplist;
Action action;
if (equipStatus.Count == 0) return;
try
{
var equipInfo = equipStatus.Where(x => x.positionId == 6).FirstOrDefault();
if (equipInfo != null)
{
if (equipInfo.IsConnect)
{
if (appConfig.machineId == 3)
{
action = () =>
{
this.TestTA.Foreground = Brushes.Green;
};
TestTA.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/正常.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus1.ImageSource = bitmapImage;
};
EquipStatus1.Dispatcher.BeginInvoke(action);
}
if (appConfig.machineId == 4)
{
action = () =>
{
this.TestTB.Foreground = Brushes.Green;
};
TestTB.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/正常.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus2.ImageSource = bitmapImage;
};
EquipStatus2.Dispatcher.BeginInvoke(action);
}
}
else
{
if (appConfig.machineId == 3)
{
action = () =>
{
this.TestTA.Foreground = Brushes.Red;
};
TestTA.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/失败-01.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus1.ImageSource = bitmapImage;
};
EquipStatus1.Dispatcher.BeginInvoke(action);
}
if (appConfig.machineId == 4)
{
action = () =>
{
this.TestTB.Foreground = Brushes.Red;
};
TestTB.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/失败-01.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus2.ImageSource = bitmapImage;
};
EquipStatus2.Dispatcher.BeginInvoke(action);
}
}
}
}
catch (Exception ex)
{
throw;
}
try
{
var equipInfo = equipStatus.Where(x => x.positionId == 5).FirstOrDefault();
if (equipInfo != null)
{
if (equipInfo.IsConnect)
{
if (appConfig.machineId == 3)
{
action = () =>
{
this.TestTB.Foreground = Brushes.Green;
};
TestTB.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/正常.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus2.ImageSource = bitmapImage;
};
EquipStatus2.Dispatcher.BeginInvoke(action);
}
if (appConfig.machineId == 4)
{
action = () =>
{
this.TestTA.Foreground = Brushes.Green;
};
TestTA.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/正常.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus1.ImageSource = bitmapImage;
};
EquipStatus1.Dispatcher.BeginInvoke(action);
}
}
else
{
if (appConfig.machineId == 3)
{
action = () =>
{
this.TestTB.Foreground = Brushes.Red;
};
TestTB.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/失败-01.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus2.ImageSource = bitmapImage;
};
EquipStatus2.Dispatcher.BeginInvoke(action);
}
if (appConfig.machineId == 4)
{
action = () =>
{
this.TestTA.Foreground = Brushes.Red;
};
TestTA.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/失败-01.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus1.ImageSource = bitmapImage;
};
EquipStatus1.Dispatcher.BeginInvoke(action);
}
}
}
}
catch (Exception ex)
{
throw;
}
try
{
var equipInfo = equipStatus.Where(x => x.positionId == 3).FirstOrDefault();
if (equipInfo != null)
{
if (equipInfo.IsConnect)
{
if (appConfig.machineId == 3)
{
action = () =>
{
this.TestTC.Foreground = Brushes.Green;
};
TestTC.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/正常.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus3.ImageSource = bitmapImage;
};
EquipStatus3.Dispatcher.BeginInvoke(action);
}
if (appConfig.machineId == 4)
{
action = () =>
{
this.TestTD.Foreground = Brushes.Green;
};
TestTD.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/正常.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus4.ImageSource = bitmapImage;
};
EquipStatus4.Dispatcher.BeginInvoke(action);
}
}
else
{
if (appConfig.machineId == 3)
{
action = () =>
{
this.TestTC.Foreground = Brushes.Red;
};
TestTC.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/失败-01.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus3.ImageSource = bitmapImage;
};
EquipStatus3.Dispatcher.BeginInvoke(action);
}
if (appConfig.machineId == 4)
{
action = () =>
{
this.TestTD.Foreground = Brushes.Red;
};
TestTD.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/失败-01.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus4.ImageSource = bitmapImage;
};
EquipStatus4.Dispatcher.BeginInvoke(action);
}
}
}
}
catch (Exception ex)
{
throw;
}
try
{
var equipInfo = equipStatus.Where(x => x.positionId == 1).FirstOrDefault();
if (equipInfo != null)
{
if (equipInfo.IsConnect)
{
if (appConfig.machineId == 3)
{
action = () =>
{
this.TestTD.Foreground = Brushes.Green;
};
TestTD.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/正常.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus4.ImageSource = bitmapImage;
};
EquipStatus4.Dispatcher.BeginInvoke(action);
}
if (appConfig.machineId == 4)
{
action = () =>
{
this.TestTC.Foreground = Brushes.Green;
};
TestTC.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/正常.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus3.ImageSource = bitmapImage;
};
EquipStatus3.Dispatcher.BeginInvoke(action);
}
}
else
{
if (appConfig.machineId == 3)
{
action = () =>
{
this.TestTD.Foreground = Brushes.Red;
};
TestTD.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/失败-01.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus4.ImageSource = bitmapImage;
};
EquipStatus4.Dispatcher.BeginInvoke(action);
}
if (appConfig.machineId == 4)
{
action = () =>
{
this.TestTC.Foreground = Brushes.Red;
};
TestTC.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/失败-01.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus3.ImageSource = bitmapImage;
};
EquipStatus3.Dispatcher.BeginInvoke(action);
}
}
}
}
catch (Exception ex)
{
throw;
}
try
{
var equipInfo = equipStatus.Where(x => x.positionId == 4).FirstOrDefault();
if (equipInfo != null)
{
if (equipInfo.IsConnect)
{
if (appConfig.machineId == 3)
{
action = () =>
{
this.TestTE.Foreground = Brushes.Green;
};
TestTE.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/正常.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus5.ImageSource = bitmapImage;
};
EquipStatus5.Dispatcher.BeginInvoke(action);
}
if (appConfig.machineId == 4)
{
action = () =>
{
this.TestTF.Foreground = Brushes.Green;
};
TestTF.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/正常.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus6.ImageSource = bitmapImage;
};
EquipStatus6.Dispatcher.BeginInvoke(action);
}
}
else
{
if (appConfig.machineId == 3)
{
action = () =>
{
this.TestTE.Foreground = Brushes.Red;
};
TestTE.Dispatcher.BeginInvoke(action);
}
if (appConfig.machineId == 4)
{
action = () =>
{
this.TestTF.Foreground = Brushes.Red;
};
TestTF.Dispatcher.BeginInvoke(action);
}
}
}
}
catch (Exception ex)
{
throw;
}
try
{
var equipInfo = equipStatus.Where(x => x.positionId == 2).FirstOrDefault();
if (equipInfo != null)
{
if (equipInfo.IsConnect)
{
if (appConfig.machineId == 3)
{
action = () =>
{
this.TestTF.Foreground = Brushes.Green;
};
TestTF.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/正常.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus6.ImageSource = bitmapImage;
};
EquipStatus6.Dispatcher.BeginInvoke(action);
}
if (appConfig.machineId == 4)
{
action = () =>
{
this.TestTE.Foreground = Brushes.Green;
};
TestTE.Dispatcher.BeginInvoke(action);
action = () =>
{
string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/正常.png";
BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl));
this.EquipStatus5.ImageSource = bitmapImage;
};
EquipStatus5.Dispatcher.BeginInvoke(action);
}
}
else
{
if (appConfig.machineId == 3)
{
action = () =>
{
this.TestTF.Foreground = Brushes.Red;
};
TestTF.Dispatcher.BeginInvoke(action);
}
if (appConfig.machineId == 4)
{
action = () =>
{
this.TestTE.Foreground = Brushes.Red;
};
TestTE.Dispatcher.BeginInvoke(action);
}
}
}
}
catch (Exception ex)
{
throw;
}
}
///
/// 上左收卷完工
///
///
///
private void UpLeftFinish_Cilck(object sender, RoutedEventArgs e)
{
int roleId = Convert.ToInt32(ConfigHelper.GetConfig("roleId"));
if (roleId > 3 || roleId == 0)
{
System.Windows.MessageBox.Show($"请登录系统管理账号进行操作,当前用户角色ID:{roleId}");
}
else
{
MessageBox.Show("上左收卷强制下料");
ListBoxItemAdd(this.PlcLog, "上左收卷强制下料触发成功,MW24824写入0");
LogHelperBusiness.LogInfo("上左收卷强制下料触发,MW24824写入0");
plcBusiness.writePlc(appConfig.mqAddress.上左收卷下料, 0);
int position = 0;
if(appConfig.machineId == 3)
{
position = 3;
}
else
{
position = 1;
}
ForcedUnloading(position);
}
}
///
/// 上右收卷完工
///
///
///
private void UpRightFinish_Cilck(object sender, RoutedEventArgs e)
{
int roleId = Convert.ToInt32(ConfigHelper.GetConfig("roleId"));
if (roleId > 3 || roleId == 0)
{
System.Windows.MessageBox.Show($"请登录系统管理账号进行操作,当前用户角色ID:{roleId}");
}
else
{
MessageBox.Show("上右收卷强制下料触发");
ListBoxItemAdd(this.PlcLog, "上右收卷强制下料触发成功,MW24826写入0");
LogHelperBusiness.LogInfo("上右收卷强制下料触发成功,MW24826写入0");
plcBusiness.writePlc(appConfig.mqAddress.上右收卷下料, 0);
int position = 0;
if (appConfig.machineId == 3)
{
position = 1;
}
else
{
position = 3;
}
ForcedUnloading(position);
}
}
///
/// 下左收卷
///
///
///
private void DownLeftFinish_Cilck(object sender, RoutedEventArgs e)
{
int roleId = Convert.ToInt32(ConfigHelper.GetConfig("roleId"));
if (roleId > 3 || roleId == 0)
{
System.Windows.MessageBox.Show($"请登录系统管理账号进行操作,当前用户角色ID:{roleId}");
}
else
{
MessageBox.Show("下左收卷强制下料触发");
ListBoxItemAdd(this.PlcLog, "下左收卷强制下料触发成功,MW24828写入0");
LogHelperBusiness.LogInfo("下左收卷强制下料触发成功,MW24828写入0");
plcBusiness.writePlc(appConfig.mqAddress.下左收卷下料, 0);
int position = 0;
if (appConfig.machineId == 3)
{
position = 4;
}
else
{
position = 2;
}
ForcedUnloading(position);
}
}
///
/// 下右收卷完工
///
///
///
private void DownRightFinish_Cilck(object sender, RoutedEventArgs e)
{
int roleId = Convert.ToInt32(ConfigHelper.GetConfig("roleId"));
if (roleId > 3 || roleId == 0)
{
System.Windows.MessageBox.Show($"请登录系统管理账号进行操作,当前用户角色ID:{roleId}");
}
else
{
MessageBox.Show("下右收卷强制下料触发");
ListBoxItemAdd(this.PlcLog, "下右收卷强制下料触发成功,MW24830写入0");
LogHelperBusiness.LogInfo("下右收卷强制下料触发成功,MW24830写入0");
plcBusiness.writePlc(appConfig.mqAddress.下右收卷下料, 0);
int position = 0;
if (appConfig.machineId == 3)
{
position = 2;
}
else
{
position = 4;
}
ForcedUnloading(position);
}
}
private void upMaterial_1_MouseDown(object sender, MouseButtonEventArgs e)
{
if (appConfig.machineId == 3)
{
position = 6;
}
else
{
position = 5;
}
WriteInfo write = new WriteInfo("MQ_A", position);
write.ShowDialog();
RefreshMaterialInfo("MQ_A", position.ToString());
}
private void upMaterial_2_MouseDown(object sender, MouseButtonEventArgs e)
{
if (appConfig.machineId == 3)
{
position = 5;
}
else
{
position = 6;
}
WriteInfo write = new WriteInfo("MQ_A", position);
write.ShowDialog();
RefreshMaterialInfo("MQ_A", position.ToString());
}
private void StackPanel_MouseDown(object sender, MouseButtonEventArgs e)
{
if (appConfig.machineId == 3)
{
position = 3;
}
else
{
position = 1;
}
WriteInfo write = new WriteInfo("MQ_A", position);
write.ShowDialog();
RefreshMaterialInfo("MQ_A", position.ToString());
}
private void down_2_MouseDown(object sender, MouseButtonEventArgs e)
{
if (appConfig.machineId == 3)
{
position = 1;
}
else
{
position = 3;
}
WriteInfo write = new WriteInfo("MQ_A", position);
write.ShowDialog();
RefreshMaterialInfo("MQ_A", position.ToString());
}
private void down_e_MouseDown(object sender, MouseButtonEventArgs e)
{
if (appConfig.machineId == 3)
{
position = 4;
}
else
{
position = 2;
}
WriteInfo write = new WriteInfo("MQ_A", position);
write.ShowDialog();
RefreshMaterialInfo("MQ_A", position.ToString());
}
private void down_4_MouseDown(object sender, MouseButtonEventArgs e)
{
if (appConfig.machineId == 3)
{
position = 2;
}
else
{
position = 4;
}
WriteInfo write = new WriteInfo("MQ_A", position);
write.ShowDialog();
RefreshMaterialInfo("MQ_A", position.ToString());
}
///
/// 刷新界面卷轴信息
///
///
///
public void RefreshMaterialInfo(string processId, string position)
{
DateTime beginTime = DateTime.Now.AddHours(-5);
Expression> exp = s1 => true;
exp = exp.And(x => x.processId == appConfig.processId && Convert.ToDateTime(x.bindTime) > beginTime);
Expression> order = s1 => s1.bindTime;
ProShaftInfo shaftInfo = shaftInfoServices.QueryFirst(exp, order, false).Result;
if (shaftInfo == null)
{
//ListBoxItemAdd(this.RfidLog, "获取卷轴数据为空");
return;
}
ProductionParam(new ViewModelDto()
{
rfidInfo = new RfidInfoDto()
{
rfid = shaftInfo.bindRfid,
sfc = shaftInfo.bindSfc,
ea = shaftInfo.bindEaValue,
position = Convert.ToInt32(shaftInfo.positionId)
}
});
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
UpdataDeviceStatus();
}
///
/// 左放卷强制下料
///
///
///
private void LeftFinish_Cilck(object sender, RoutedEventArgs e)
{
int roleId = Convert.ToInt32(ConfigHelper.GetConfig("roleId"));
if (roleId > 3 || roleId == 0)
{
System.Windows.MessageBox.Show($"请登录系统管理账号进行操作,当前用户角色ID:{roleId}");
}
else
{
MessageBox.Show("左放卷强制下料");
ListBoxItemAdd(this.PlcLog, "左放卷强制下料触发成功");
LogHelperBusiness.LogInfo("左放卷强制下料触发");
plcBusiness.writePlc(appConfig.mqAddress.左放卷下料, 0);
}
}
///
/// 右放卷强制下料
///
///
///
private void RightFinish_Cilck(object sender, RoutedEventArgs e)
{
int roleId = Convert.ToInt32(ConfigHelper.GetConfig("roleId"));
if (roleId > 3 || roleId == 0)
{
System.Windows.MessageBox.Show($"请登录系统管理账号进行操作,当前用户角色ID:{roleId}");
}
else
{
MessageBox.Show("右放卷强制下料");
ListBoxItemAdd(this.PlcLog, "右放卷强制下料触发成功");
LogHelperBusiness.LogInfo("右放卷强制下料触发");
plcBusiness.writePlc(appConfig.mqAddress.右放卷下料, 0);
}
}
///
/// 强制下料清除绑定信息解除合卷报警
///
///
private void ForcedUnloading(int position)
{
try
{
string logStr = Which(position);
ProShaftInfo shaftInfo = this.GetShaftInfoByPosition(position).Result;
if (shaftInfo != null)
{
shaftInfo.bindRfid = "";
shaftInfo.bindSfc = "";
shaftInfo.bindEaValue = "";
shaftInfo.bindTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
shaftInfoServices.Update(shaftInfo);
}
ListBoxItemAdd(this.PlcLog, logStr + "强制下料触发成功,解除合卷报警");
LogHelperBusiness.LogInfo(logStr + "强制下料触发成功,解除合卷报警");
plcBusiness.writeDoublePlc(appConfig.mqAddress.全局报警, 0);
}catch(Exception ex)
{
LogHelperBusiness.LogInfo("强制下料异常:"+ex.Message);
}
}
///
/// 根据设备位置获取卷轴信息
///
///
///
private async Task GetShaftInfoByPosition(int position)
{
try
{
string str = appConfig.processId;
Expression> exp = s1 => true;
exp = exp.And(x => x.positionId == position.ToString() && x.processId == str);
List result = await shaftInfoServices.Query(exp);
if (result != null || result.Count > 0)
{
ProShaftInfo shaftInfo = result.FirstOrDefault();
return shaftInfo;
}
return null;
}
catch (Exception ex)
{
LogHelperBusiness.LogInfo("获取绑定信息异常:"+ex.Message);
return null;
}
}
///
///判断当前是哪个轴
///
///
private string Which(int position)
{
string logStr = "";
if (appConfig.machineId == 3)
{
if (position == 3) logStr = "上收卷左";
if (position == 1) logStr = "上收卷右";
if (position == 4) logStr = "下收卷左";
if (position == 2) logStr = "下收卷右";
if (position == 5) logStr = "右放卷";
if (position == 6) logStr = "左放卷";
}
else
{
if (position == 1) logStr = "上收卷左";
if (position == 3) logStr = "上收卷右";
if (position == 2) logStr = "下收卷左";
if (position == 4) logStr = "下收卷右";
if (position == 5) logStr = "左放卷";
if (position == 6) logStr = "右放卷";
}
return logStr;
}
}
}