using HslCommunication.Core.IMessage; using LogForceTestApp.Modules.MainModule.Models; using LogoForceTestApp.Modules.MainModule.Enums; using LogoForceTestApp.Modules.MainModule.Models; using LogoForceTestApp.Modules.MainModule.Services; using LogoForceTestApp.Services; using LogoForceTestApp.Services.Interfaces; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using OxyPlot; using OxyPlot.Axes; using OxyPlot.Series; using Prism.Commands; using Prism.Events; using Prism.Mvvm; using Prism.Regions; using Prism.Services.Dialogs; using PropertyChanged; using Repository; using Repository.Entiies; using Serilog; using SkiaSharp.QrCode; //生成二维码 using SkiaSharp; using StatementMachineService.Core; using StatementMachineService.Events; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Net.Http; using System.Runtime.Serialization; using System.Security.Cryptography; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Timers; using System.Windows; using Team.Utility; using static AutoMapper.Internal.ExpressionFactory; using System.Collections.ObjectModel; using TouchSocket.Core; using TouchSocket.Sockets; using Result = LogoForceTestApp.Modules.MainModule.Models.Result; using System.Windows.Media; using SkiaSharp.Views.WPF; using System.Windows.Media.Imaging; using System.Windows.Media.Media3D; using System.Drawing; using ZXing.Common; using ZXing; using HandyControl.Controls; using LogoForceTestApp.Core; using System.Windows.Documents; using System.Data.SqlTypes; using HandyControl.Data; using static SkiaSharp.HarfBuzz.SKShaper; using System.Windows.Forms; using Application = System.Windows.Application; using LogoForceTestApp.Modules.MainModule.Views; namespace LogoForceTestApp.Modules.MainModule.ViewModels { public class MainPageViewModel : BindableBase { int _upLoadSlowTime; private bool _start; private List<DataPoint> _points = new(); private readonly ConcurrentQueue<UpLoadTraceModel> _upLoadTraceModels = new(); private readonly IHttpClientFactory _httpClientFactory; private readonly IScanService _scanService; private readonly IModbusTcpSlaverService _modbusTcpSlaverService; private readonly IStateService _stateService; private readonly IRepository _repository; private readonly IWritableOptions<AppSettings> _appSttings; private readonly IEventAggregator _eventAggregator; //private readonly InovanceTcp inovanceTcp; private readonly PLC tcpNet; private readonly ILogger _logger; private readonly IWarningUpdateService _warningUpdateService; private readonly IDialogService _dialogService; private readonly TcpService tcpService; private readonly Dictionary<int, string> SignalMapper; private bool _firstStart = true; private ResettableTimer _resettableTimer; public ObservableCollection<InformationNew> InforNew { get; set; } [DoNotNotify] public string CSVPath { get; set; } [DoNotNotify] public string ImagePath { get; set; } private bool _connected; public bool Connected { get { return _connected; } set { _connected = value; } } public DelegateCommand QRCommand { get; set; } public DelegateCommand HouseCommand { get; set; } public DelegateCommand OutWorkCommand { get; set; } public DelegateCommand OrderCommand { get; set; } //public string SelectedOrderName { get; set; } //public ObservableCollection<string> OrderNames { get; set; } public string Order { get; set; } public string LackHouse { get; set; } public string UsedHouse { get; set; } public string TotalHouse { get; set; } public int ActPer { get; set; } public int FallPer { get; set; } public int AbsPer { get; set; } #region Operator public string Operator1 { get; set; } public string Operator2 { get; set; } public string Operator3 { get; set; } public string Operator4 { get; set; } public string Operator5 { get; set; } public string Operator6 { get; set; } public string Operator7 { get; set; } public string Operator8 { get; set; } public string Operator9 { get; set; } public string Operator10 { get; set; } public string Operator11 { get; set; } public string Operator12 { get; set; } public string Operator13 { get; set; } public string Operator14 { get; set; } public string Operator15 { get; set; } public string Operator16 { get; set; } public string Operator17 { get; set; } public string Operator18 { get; set; } public string Operator19 { get; set; } public string Operator20 { get; set; } public string Operator21 { get; set; } #endregion #region Material public string Material1 { get; set; } public string Material2 { get; set; } public string Material3 { get; set; } public string Material4 { get; set; } public string Material5 { get; set; } public string Material6 { get; set; } public string Material7 { get; set; } public string Material8 { get; set; } public string Material9 { get; set; } public string Material10 { get; set; } public string Material11 { get; set; } public string Material12 { get; set; } public string Material13 { get; set; } public string Material14 { get; set; } public string Material15 { get; set; } public string Material16 { get; set; } public string Material17 { get; set; } public string Material18 { get; set; } public string Material19 { get; set; } public string Material20 { get; set; } public string Material21 { get; set; } #endregion #region 物料 public ObservableCollection<string> listMaterial1 { get; set; } public ObservableCollection<string> listMaterial2 { get; set; } public ObservableCollection<string> listMaterial3 { get; set; } public ObservableCollection<string> listMaterial4 { get; set; } public ObservableCollection<string> listMaterial5 { get; set; } public ObservableCollection<string> listMaterial6 { get; set; } public ObservableCollection<string> listMaterial7 { get; set; } public ObservableCollection<string> listMaterial8 { get; set; } public ObservableCollection<string> listMaterial9 { get; set; } public ObservableCollection<string> listMaterial10 { get; set; } public ObservableCollection<string> listMaterial11 { get; set; } public ObservableCollection<string> listMaterial12 { get; set; } public ObservableCollection<string> listMaterial13 { get; set; } public ObservableCollection<string> listMaterial14 { get; set; } #endregion public string ProductCode { get; set; } string soleNum = null; int[] q = new int[30]; string[] operName = new string[25]; private System.Timers.Timer _timer; private Thread myBackUpThread; public MainPageViewModel(IHttpClientFactory httpClientFactory, IScanService scanService, IModbusTcpSlaverService modbusTcpSlaverService, IStateService stateService, IRepository repository, IWritableOptions<AppSettings> appSttings, IEventAggregator eventAggregator, PLC tcpNet, ILogger logger, IWarningUpdateService warningUpdateService, IDialogService dialogService, TcpService tcpService) { _httpClientFactory = httpClientFactory; _scanService = scanService; _modbusTcpSlaverService = modbusTcpSlaverService; _stateService = stateService; _repository = repository; _appSttings = appSttings; CSVPath = _appSttings.Value.CSVPath; ImagePath = _appSttings.Value.ImageSavePath; _eventAggregator = eventAggregator; this.tcpNet = tcpNet; _logger = logger; _warningUpdateService = warningUpdateService; _dialogService = dialogService; this.tcpService = tcpService; InforNew = new ObservableCollection<InformationNew>(); HouseCommand = new DelegateCommand(UploadHouse); OutWorkCommand = new DelegateCommand(UploadOutWork); OrderCommand = new DelegateCommand(OrderEnter); Connected = tcpNet.Connect(); #region tcpService tcpService.Connected = (client, e) => { WriteLog("有客户端成功连接"); return EasyTask.CompletedTask; };//有客户端成功连接 tcpService.Disconnecting = (client, e) => { return EasyTask.CompletedTask; };//有客户端正在断开连接,只有当主动断开时才有效。 tcpService.Disconnected = (client, e) => { WriteLog("有客户端断开连接"); return EasyTask.CompletedTask; };//有客户端断开连接 tcpService.Received = (client, e) => { //从客户端收到信息 var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意:数据长度是byteBlock.Len //WriteLog($"已从{client.Id}接收到信息:{mes}"); //client.Send(mes); //WriteLog("发送" + mes); try { #region 1-7 if (client.IP == "192.168.10.1")//1号机 { if (mes.Split(":")[0] == "WU") { Material1 = ResWord(mes.Split(":")[1]); //listMaterial1.Add(mes.Split(":")[1]); client.Send($"WU:物料上传成功"); WriteLog("1#物料上传成功"); } if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator1 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("1#登录成功"); operName[0] = Operator1; } if (mes == "切换完成") { tcpNet.Write("1501.0", true); Thread.Sleep(1000); WriteLog("1#切换完成"); } tcpNet.Write("1501.0", false); } if (client.IP == "192.168.10.2")//2号机 { if (mes.Split(":")[0] == "WU") { Material2 = ResWord(mes.Split(":")[1]); client.Send($"WU:物料上传成功"); WriteLog("2#物料上传成功"); } if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator2 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("2#登录成功"); operName[1] = Operator2; } if (mes == "切换完成") { tcpNet.Write("1501.1", true); Thread.Sleep(1000); WriteLog("2#切换完成"); } tcpNet.Write("1501.1", false); } if (client.IP == "192.168.10.3")//3号机 { if (mes.Split(":")[0] == "WU") { Material3 = ResWord(mes.Split(":")[1]); client.Send($"WU:物料上传成功"); WriteLog("3#物料上传成功"); } if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator3 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("3#登录成功"); operName[2] = Operator3; } if (mes == "切换完成") { tcpNet.Write("1501.2", true); Thread.Sleep(1000); WriteLog("3#切换完成"); } tcpNet.Write("1501.2", false); } if (client.IP == "192.168.10.4")//4号机 { if (mes.Split(":")[0] == "WU") { Material4 = ResWord(mes.Split(":")[1]); client.Send($"WU:物料上传成功"); WriteLog("4#物料上传成功"); } if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator4 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("4#登录成功"); operName[3] = Operator4; } if (mes == "切换完成") { tcpNet.Write("1501.3", true); Thread.Sleep(1000); WriteLog("4#切换完成"); } tcpNet.Write("1501.3", false); } if (client.IP == "192.168.10.5")//5号机 { if (mes.Split(":")[0] == "WU") { Material5 = ResWord(mes.Split(":")[1]); client.Send($"WU:物料上传成功"); WriteLog("5#物料上传成功"); } if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator5 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("5#登录成功"); operName[4] = Operator5; } if (mes == "切换完成") { tcpNet.Write("1501.4", true); Thread.Sleep(1000); WriteLog("5#切换完成"); } tcpNet.Write("1501.4", false); } if (client.IP == "192.168.10.6")//6号机 { if (mes.Split(":")[0] == "WU") { Material6 = ResWord(mes.Split(":")[1]); client.Send($"WU:物料上传成功"); WriteLog("6#物料上传成功"); } if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator6 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("6#登录成功"); operName[5] = Operator6; } if (mes == "切换完成") { tcpNet.Write("1501.5", true); Thread.Sleep(1000); WriteLog("6#切换完成"); } tcpNet.Write("1501.5", false); } if (client.IP == "192.168.10.7")//7号机 { if (mes.Split(":")[0] == "WU") { Material7 = ResWord(mes.Split(":")[1]); client.Send($"WU:物料上传成功"); WriteLog("7#物料上传成功"); } if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator7 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("7#登录成功"); operName[6] = Operator7; } if (mes == "切换完成") { tcpNet.Write("1501.6", true); Thread.Sleep(1000); WriteLog("7#切换完成"); } tcpNet.Write("1501.6", false); } #endregion #region 7-14 if (client.IP == "192.168.10.8")//8号机 { if (mes.Split(":")[0] == "WU") { Material8 = ResWord(mes.Split(":")[1]); client.Send($"WU:物料上传成功"); WriteLog("8#物料上传成功"); } if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator8 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("8#登录成功"); operName[7] = Operator8; } if (mes == "切换完成") { tcpNet.Write("1501.7", true); Thread.Sleep(1000); WriteLog("8#切换完成"); } tcpNet.Write("1501.7", false); } if (client.IP == "192.168.10.9")//9号机 { if (mes.Split(":")[0] == "WU") { Material9 = ResWord(mes.Split(":")[1]); client.Send($"WU:物料上传成功"); WriteLog("9#物料上传成功"); } if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator9 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("9#登录成功"); operName[8] = Operator9; } if (mes == "切换完成") { tcpNet.Write("1501.8", true); Thread.Sleep(1000); WriteLog("9#切换完成"); } tcpNet.Write("1501.8", false); } if (client.IP == "192.168.10.10")//10号机 { if (mes.Split(":")[0] == "WU") { Material10 = ResWord(mes.Split(":")[1]); client.Send($"WU:物料上传成功"); WriteLog("10#物料上传成功"); } if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator10 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("10#登录成功"); operName[9] = Operator10; } if (mes == "切换完成") { tcpNet.Write("1501.9", true); Thread.Sleep(1000); WriteLog("10#切换完成"); } tcpNet.Write("1501.9", false); } if (client.IP == "192.168.10.11")//11号机 { if (mes.Split(":")[0] == "WU") { Material11 = ResWord(mes.Split(":")[1]); client.Send($"WU:物料上传成功"); WriteLog("11#物料上传成功"); } if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator11 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("11#登录成功"); operName[10] = Operator11; } if (mes == "切换完成") { tcpNet.Write("1501.10", true); Thread.Sleep(1000); WriteLog("11#切换完成"); } tcpNet.Write("1501.10", false); } if (client.IP == "192.168.10.12")//12号机 { if (mes.Split(":")[0] == "WU") { Material12 = ResWord(mes.Split(":")[1]); client.Send($"WU:物料上传成功"); WriteLog("12#物料上传成功"); } if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator12 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("12#登录成功"); operName[11] = Operator12; } if (mes == "切换完成") { tcpNet.Write("1501.11", true); Thread.Sleep(1000); WriteLog("12#切换完成"); } tcpNet.Write("1501.11", false); } if (client.IP == "192.168.10.13")//13号机 { if (mes.Split(":")[0] == "WU") { Material13 = ResWord(mes.Split(":")[1]); client.Send($"WU:物料上传成功"); WriteLog("13#物料上传成功"); } if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator13 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("13#登录成功"); operName[12] = Operator13; } if (mes == "切换完成") { tcpNet.Write("1501.12", true); Thread.Sleep(1000); WriteLog("13#切换完成"); } tcpNet.Write("1501.12", false); } if (client.IP == "192.168.10.14")//14号机 { if (mes.Split(":")[0] == "WU") { Material14 = ResWord(mes.Split(":")[1]); client.Send($"WU:物料上传成功"); WriteLog("14#物料上传成功"); } if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator14 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("14#登录成功"); operName[13] = Operator14; } if (mes == "切换完成") { tcpNet.Write("1501.13", true); Thread.Sleep(1000); WriteLog("14#切换完成"); } tcpNet.Write("1501.13", false); } #endregion #region 检测机 if (client.IP == "192.168.10.15")//检测1 { if (mes.Split(":")[0] == "Bind") { Bind(mes.Split(":")[1]); client.Send("B:绑定成功"); WriteLog("检测1#绑定成功"); } if (mes.Split(":")[0] == "TestRes") { string sp = mes.Split(":")[1];//产品码 string result = mes.Split(":")[2]; string opname = Operator15; TestRes(sp, result, opname); WriteCSV_Test(opname, sp, result); client.Send("TeR:检测结果上传成功"); WriteLog("检测1#检测结果上传成功"); } if (mes.Split(":")[0] == "Test") { for (int i = 0; i < 30; i++) { if (mes.Split(":")[i + 1] == "1") { q[i] = 1; } else { q[i] = 0; } } //string str = DateTime.Now.ToString("yyyy/MM/dd"); DateTime dt = DateTime.Today; var list = repository.GetFirstDefault<Quality>(c => c.DateQuality == dt);//查一个值 if (list != null) { list.Q1 = list.Q1 + q[0]; list.Q2 = list.Q2 + q[1]; list.Q3 = list.Q3 + q[2]; list.Q4 = list.Q4 + q[3]; list.Q5 = list.Q5 + q[4]; list.Q6 = list.Q6 + q[5]; list.Q7 = list.Q7 + q[6]; list.Q8 = list.Q8 + q[7]; list.Q9 = list.Q9 + q[8]; list.Q10 = list.Q10 + q[9]; list.Q11 = list.Q11 + q[10]; list.Q12 = list.Q12 + q[11]; list.Q13 = list.Q13 + q[12]; list.Q14 = list.Q14 + q[13]; list.Q15 = list.Q15 + q[14]; list.Q16 = list.Q16 + q[15]; list.Q17 = list.Q17 + q[16]; list.Q18 = list.Q18 + q[17]; list.Q19 = list.Q19 + q[18]; list.Q20 = list.Q20 + q[19]; list.Q21 = list.Q21 + q[20]; list.Q22 = list.Q22 + q[21]; list.Q23 = list.Q23 + q[22]; list.Q24 = list.Q24 + q[23]; list.Q25 = list.Q25 + q[24]; list.Q26 = list.Q26 + q[25]; list.Q27 = list.Q27 + q[26]; list.Q28 = list.Q28 + q[27]; list.Q29 = list.Q29 + q[28]; list.Q30 = list.Q30 + q[29]; _repository.Update(list); client.Send("Te:上传成功"); WriteLog("检测1#上传成功"); } else { var item = new Quality() { Id = Guid.NewGuid(), DateQuality = dt, Q1 = q[0], Q2 = q[1], Q3 = q[2], Q4 = q[3], Q5 = q[4], Q6 = q[5], Q7 = q[6], Q8 = q[7], Q9 = q[8], Q10 = q[9], Q11 = q[10], Q12 = q[11], Q13 = q[12], Q14 = q[13], Q15 = q[14], Q16 = q[15], Q17 = q[16], Q18 = q[17], Q19 = q[18], Q20 = q[19], Q21 = q[20], Q22 = q[21], Q23 = q[22], Q24 = q[23], Q25 = q[24], Q26 = q[25], Q27 = q[26], Q28 = q[27], Q29 = q[28], Q30 = q[29], }; _repository.Add(item); client.Send("Te:上传成功"); WriteLog("检测1#上传成功"); } } if (mes == "切换完成") { tcpNet.Write("1501.14", true); Thread.Sleep(1000); WriteLog("检测1#切换完成"); } tcpNet.Write("1501.14", false); if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator15 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("15#登录成功"); operName[14] = Operator15; } } if (client.IP == "192.168.10.16")//检测2 { if (mes.Split(":")[0] == "TestRes") { string sp = mes.Split(":")[1]; string result = mes.Split(":")[2]; string opname = Operator16; TestRes(sp, result, opname); WriteCSV_Test(opname, sp, result); client.Send("TeR:检测结果上传成功"); WriteLog("检测2#检测结果上传成功"); } if (mes.Split(":")[0] == "Test") { for (int i = 0; i < 30; i++) { if (mes.Split(":")[i + 1] == "1") { q[i] = 1; } else { q[i] = 0; } } DateTime dt = DateTime.Today; var list = repository.GetFirstDefault<Quality>(c => c.DateQuality == dt);//查一个值 if (list != null) { list.Q1 = list.Q1 + q[0]; list.Q2 = list.Q2 + q[1]; list.Q3 = list.Q3 + q[2]; list.Q4 = list.Q4 + q[3]; list.Q5 = list.Q5 + q[4]; list.Q6 = list.Q6 + q[5]; list.Q7 = list.Q7 + q[6]; list.Q8 = list.Q8 + q[7]; list.Q9 = list.Q9 + q[8]; list.Q10 = list.Q10 + q[9]; list.Q11 = list.Q11 + q[10]; list.Q12 = list.Q12 + q[11]; list.Q13 = list.Q13 + q[12]; list.Q14 = list.Q14 + q[13]; list.Q15 = list.Q15 + q[14]; list.Q16 = list.Q16 + q[15]; list.Q17 = list.Q17 + q[16]; list.Q18 = list.Q18 + q[17]; list.Q19 = list.Q19 + q[18]; list.Q20 = list.Q20 + q[19]; list.Q21 = list.Q21 + q[20]; list.Q22 = list.Q22 + q[21]; list.Q23 = list.Q23 + q[22]; list.Q24 = list.Q24 + q[23]; list.Q25 = list.Q25 + q[24]; list.Q26 = list.Q26 + q[25]; list.Q27 = list.Q27 + q[26]; list.Q28 = list.Q28 + q[27]; list.Q29 = list.Q29 + q[28]; list.Q30 = list.Q30 + q[29]; _repository.Update(list); client.Send("Te:上传成功"); WriteLog("检测2#上传成功"); } else { var item = new Quality() { Id = Guid.NewGuid(), DateQuality = dt, Q1 = q[0], Q2 = q[1], Q3 = q[2], Q4 = q[3], Q5 = q[4], Q6 = q[5], Q7 = q[6], Q8 = q[7], Q9 = q[8], Q10 = q[9], Q11 = q[10], Q12 = q[11], Q13 = q[12], Q14 = q[13], Q15 = q[14], Q16 = q[15], Q17 = q[16], Q18 = q[17], Q19 = q[18], Q20 = q[19], Q21 = q[20], Q22 = q[21], Q23 = q[22], Q24 = q[23], Q25 = q[24], Q26 = q[25], Q27 = q[26], Q28 = q[27], Q29 = q[28], Q30 = q[29], }; _repository.Add(item); client.Send("Te:上传成功"); WriteLog("检测2#上传成功"); } } if (mes == "切换完成") { tcpNet.Write("1501.15", true); Thread.Sleep(1000); WriteLog("检测2#切换完成"); } tcpNet.Write("1501.15", false); if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator16 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("16#登录成功"); operName[15] = Operator16; } } if (client.IP == "192.168.10.17")//检测3 { if (mes.Split(":")[0] == "TestRes") { string sp = mes.Split(":")[1]; string result = mes.Split(":")[2]; string opname = Operator17; TestRes(sp, result, opname); WriteCSV_Test(opname, sp, result); client.Send("TeR:检测结果上传成功"); WriteLog("检测3#检测结果上传成功"); } if (mes.Split(":")[0] == "Test") { for (int i = 0; i < 30; i++) { if (mes.Split(":")[i + 1] == "1") { q[i] = 1; } else { q[i] = 0; } } DateTime dt = DateTime.Today; var list = repository.GetFirstDefault<Quality>(c => c.DateQuality == dt);//查一个值 if (list != null) { list.Q1 = list.Q1 + q[0]; list.Q2 = list.Q2 + q[1]; list.Q3 = list.Q3 + q[2]; list.Q4 = list.Q4 + q[3]; list.Q5 = list.Q5 + q[4]; list.Q6 = list.Q6 + q[5]; list.Q7 = list.Q7 + q[6]; list.Q8 = list.Q8 + q[7]; list.Q9 = list.Q9 + q[8]; list.Q10 = list.Q10 + q[9]; list.Q11 = list.Q11 + q[10]; list.Q12 = list.Q12 + q[11]; list.Q13 = list.Q13 + q[12]; list.Q14 = list.Q14 + q[13]; list.Q15 = list.Q15 + q[14]; list.Q16 = list.Q16 + q[15]; list.Q17 = list.Q17 + q[16]; list.Q18 = list.Q18 + q[17]; list.Q19 = list.Q19 + q[18]; list.Q20 = list.Q20 + q[19]; list.Q21 = list.Q21 + q[20]; list.Q22 = list.Q22 + q[21]; list.Q23 = list.Q23 + q[22]; list.Q24 = list.Q24 + q[23]; list.Q25 = list.Q25 + q[24]; list.Q26 = list.Q26 + q[25]; list.Q27 = list.Q27 + q[26]; list.Q28 = list.Q28 + q[27]; list.Q29 = list.Q29 + q[28]; list.Q30 = list.Q30 + q[29]; _repository.Update(list); client.Send("Te:上传成功"); WriteLog("检测3#上传成功"); } else { var item = new Quality() { Id = Guid.NewGuid(), DateQuality = dt, Q1 = q[0], Q2 = q[1], Q3 = q[2], Q4 = q[3], Q5 = q[4], Q6 = q[5], Q7 = q[6], Q8 = q[7], Q9 = q[8], Q10 = q[9], Q11 = q[10], Q12 = q[11], Q13 = q[12], Q14 = q[13], Q15 = q[14], Q16 = q[15], Q17 = q[16], Q18 = q[17], Q19 = q[18], Q20 = q[19], Q21 = q[20], Q22 = q[21], Q23 = q[22], Q24 = q[23], Q25 = q[24], Q26 = q[25], Q27 = q[26], Q28 = q[27], Q29 = q[28], Q30 = q[29], }; _repository.Add(item); client.Send("Te:上传成功"); WriteLog("检测3#上传成功"); } } if (mes == "切换完成") { tcpNet.Write("1502.0", true); Thread.Sleep(1000); WriteLog("检测3#切换完成"); } tcpNet.Write("1502.0", false); if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator17 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("17#登录成功"); operName[16] = Operator17; } } if (client.IP == "192.168.10.18")//检测4 { if (mes.Split(":")[0] == "TestRes") { string sp = mes.Split(":")[1]; string result = mes.Split(":")[2]; string opname = Operator18; TestRes(sp, result, opname); WriteCSV_Test(opname, sp, result); client.Send("TeR:检测结果上传成功"); WriteLog("检测4#检测结果上传成功"); } if (mes.Split(":")[0] == "Test") { for (int i = 0; i < 30; i++) { if (mes.Split(":")[i + 1] == "1") { q[i] = 1; } else { q[i] = 0; } } DateTime dt = DateTime.Today; var list = repository.GetFirstDefault<Quality>(c => c.DateQuality == dt);//查一个值 if (list != null) { list.Q1 = list.Q1 + q[0]; list.Q2 = list.Q2 + q[1]; list.Q3 = list.Q3 + q[2]; list.Q4 = list.Q4 + q[3]; list.Q5 = list.Q5 + q[4]; list.Q6 = list.Q6 + q[5]; list.Q7 = list.Q7 + q[6]; list.Q8 = list.Q8 + q[7]; list.Q9 = list.Q9 + q[8]; list.Q10 = list.Q10 + q[9]; list.Q11 = list.Q11 + q[10]; list.Q12 = list.Q12 + q[11]; list.Q13 = list.Q13 + q[12]; list.Q14 = list.Q14 + q[13]; list.Q15 = list.Q15 + q[14]; list.Q16 = list.Q16 + q[15]; list.Q17 = list.Q17 + q[16]; list.Q18 = list.Q18 + q[17]; list.Q19 = list.Q19 + q[18]; list.Q20 = list.Q20 + q[19]; list.Q21 = list.Q21 + q[20]; list.Q22 = list.Q22 + q[21]; list.Q23 = list.Q23 + q[22]; list.Q24 = list.Q24 + q[23]; list.Q25 = list.Q25 + q[24]; list.Q26 = list.Q26 + q[25]; list.Q27 = list.Q27 + q[26]; list.Q28 = list.Q28 + q[27]; list.Q29 = list.Q29 + q[28]; list.Q30 = list.Q30 + q[29]; _repository.Update(list); client.Send("Te:上传成功"); WriteLog("检测4#上传成功"); } else { var item = new Quality() { Id = Guid.NewGuid(), DateQuality = dt, Q1 = q[0], Q2 = q[1], Q3 = q[2], Q4 = q[3], Q5 = q[4], Q6 = q[5], Q7 = q[6], Q8 = q[7], Q9 = q[8], Q10 = q[9], Q11 = q[10], Q12 = q[11], Q13 = q[12], Q14 = q[13], Q15 = q[14], Q16 = q[15], Q17 = q[16], Q18 = q[17], Q19 = q[18], Q20 = q[19], Q21 = q[20], Q22 = q[21], Q23 = q[22], Q24 = q[23], Q25 = q[24], Q26 = q[25], Q27 = q[26], Q28 = q[27], Q29 = q[28], Q30 = q[29], }; _repository.Add(item); client.Send("Te:上传成功"); WriteLog("检测4#上传成功"); } } if (mes == "切换完成") { tcpNet.Write("1502.1", true); Thread.Sleep(1000); WriteLog("检测4#切换完成"); } tcpNet.Write("1502.1", false); if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator18 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("18#登录成功"); operName[17] = Operator18; } } #endregion #region 维修机 if (client.IP == "192.168.10.19")//维修1 { if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator19 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("19#登录成功"); operName[18] = Operator19; } if (mes.Split(":")[0] == "Fix") { string sp = mes.Split(":")[1]; string wu = ResWord(mes.Split(":")[2]); var res = repository.GetFirstDefault<Information>(c => c.ProCode == sp); if (res != null) { Application.Current.Dispatcher.Invoke(new Action(() => { var productNew = new InformationNew { OperatorCode = Operator19, ItemCode = wu, SpendTime = 0, CreateTime = DateTime.Today, ProType = proName, ProNo = "", ProCode = sp, OrderNo = "", TestResult = "维修" }; var product = new Information() { CreateTime = productNew.CreateTime, Id = Guid.NewGuid(), OperatorCode = productNew.OperatorCode, ItemCode = productNew.ItemCode, SpendTime = productNew.SpendTime, ProType = productNew.ProType, ProNo = productNew.ProNo, ProCode = productNew.ProCode, OrderNo = productNew.OrderNo, TestResult = productNew.TestResult }; InforNew.Add(productNew); _repository.Add(product); })); WriteCSV_Repair(Operator19, sp, wu); client.Send("Rep:维修信息上传成功"); WriteLog("维修1#维修信息上传成功"); try { var list = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);//查一个值 if (list != null) { list.ErrS++; _repository.Update(list); } var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == DateTime.Today); if (allnumbers != null) { allnumbers.ErrA++; _repository.Update(allnumbers); } } catch (Exception ex) { WriteLog("FIX1:" + ex.Message, LogType.Error); } } } } if (client.IP == "192.168.10.20")//维修2 { if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator20 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("20#登录成功"); operName[19] = Operator20; } if (mes.Split(":")[0] == "Fix") { string sp = mes.Split(":")[1]; string wu = ResWord(mes.Split(":")[2]); var res = repository.GetFirstDefault<Information>(c => c.ProCode == sp); if (res != null) { Application.Current.Dispatcher.Invoke(new Action(() => { var productNew = new InformationNew { OperatorCode = Operator20, ItemCode = wu, SpendTime = 0, CreateTime = DateTime.Today, ProType = proName, ProNo = "", ProCode = sp, OrderNo = "", TestResult = "维修" }; var product = new Information() { CreateTime = productNew.CreateTime, Id = Guid.NewGuid(), OperatorCode = productNew.OperatorCode, ItemCode = productNew.ItemCode, SpendTime = productNew.SpendTime, ProType = productNew.ProType, ProNo = productNew.ProNo, ProCode = productNew.ProCode, OrderNo = productNew.OrderNo, TestResult = productNew.TestResult }; InforNew.Add(productNew); _repository.Add(product); })); WriteCSV_Repair(Operator20, sp, wu); client.Send("Rep:维修信息上传成功"); WriteLog("维修2#维修信息上传成功"); try { var list = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);//查一个值 if (list != null) { list.ErrS++; _repository.Update(list); } var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == DateTime.Today); if (allnumbers != null) { allnumbers.ErrA++; _repository.Update(allnumbers); } } catch (Exception ex) { WriteLog("FIX2:" + ex.Message, LogType.Error); } } } } if (client.IP == "192.168.10.21")//维修3 { if (mes.Split(":")[0] == "Login") { string accountID = mes.Split(":")[1]; Operator21 = accountID; client.Send($"LoginSuc:登录成功"); WriteLog("21#登录成功"); operName[20] = Operator21; } if (mes.Split(":")[0] == "Fix") { string sp = mes.Split(":")[1]; string wu = ResWord(mes.Split(":")[2]); var res = repository.GetFirstDefault<Information>(c => c.ProCode == sp); if (res != null) { Application.Current.Dispatcher.Invoke(new Action(() => { var productNew = new InformationNew { OperatorCode = Operator21, ItemCode = wu, SpendTime = 0, CreateTime = DateTime.Today, ProType = proName, ProNo = "", ProCode = sp, OrderNo = "", TestResult = "维修" }; var product = new Information() { CreateTime = productNew.CreateTime, Id = Guid.NewGuid(), OperatorCode = productNew.OperatorCode, ItemCode = productNew.ItemCode, SpendTime = productNew.SpendTime, ProType = productNew.ProType, ProNo = productNew.ProNo, ProCode = productNew.ProCode, OrderNo = productNew.OrderNo, TestResult = productNew.TestResult }; InforNew.Add(productNew); _repository.Add(product); })); WriteCSV_Repair(Operator21, sp, wu); client.Send("Rep:维修信息上传成功"); WriteLog("维修3#维修信息上传成功"); try { var list = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);//查一个值 if (list != null) { list.ErrS++; _repository.Update(list); } var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == DateTime.Today); if (allnumbers != null) { allnumbers.ErrA++; _repository.Update(allnumbers); } } catch (Exception ex) { WriteLog("FIX3:" + ex.Message, LogType.Error); } } } } #endregion OperatorName(operName); } catch (Exception ex) { WriteLog($"TCPReceived:{ex.Message}"); } return EasyTask.CompletedTask; }; #endregion SignalMapper = new Dictionary<int, string> { {1, "1025.0" }, {2, "1025.1" }, {3, "1025.2" }, {4, "1025.3" }, {5, "1025.4" }, {6, "1025.5" }, {7, "1025.8" }, {8, "1025.9" }, {9, "1025.10" }, {10, "1025.11" }, {11, "1025.14" }, {12, "1025.15" }, {13, "1026.0" }, {14, "1026.1" }, {15, "1026.4" },//完成 }; _stateService.CreateMachine(1, RecordOneMessage1, null); _stateService.CreateMachine(2, RecordOneMessage2, null); _stateService.CreateMachine(3, RecordOneMessage3, null); _stateService.CreateMachine(4, RecordOneMessage4, null); _stateService.CreateMachine(5, RecordOneMessage5, null); _stateService.CreateMachine(6, RecordOneMessage6, null); _stateService.CreateMachine(7, RecordOneMessage7, null); _stateService.CreateMachine(8, RecordOneMessage8, null); _stateService.CreateMachine(9, RecordOneMessage9, null); _stateService.CreateMachine(10, RecordOneMessage10, null); _stateService.CreateMachine(11, RecordOneMessage11, null); _stateService.CreateMachine(12, RecordOneMessage12, null); _stateService.CreateMachine(13, RecordOneMessage13, null); _stateService.CreateMachine(14, RecordOneMessage14, null); _stateService.CreateMachine(15, ProcessFinish, null); Task.Factory.StartNew(Timer_Elapsed, TaskCreationOptions.LongRunning); Task.Factory.StartNew(Timer_Elapsed2, TaskCreationOptions.LongRunning); Task.Factory.StartNew(Timer_Elapsed3, TaskCreationOptions.LongRunning); QRCommand = new DelegateCommand(QRcode); //_eventAggregator.GetEvent<FileChangedEvent>().Subscribe(ReadConfig); myBackUpThread = new Thread(_timer_Elapsed1) { IsBackground = true }; myBackUpThread.Start(); } public void Bind(string procode) { var res = _repository.GetAllQuery<Information>(c => c.ProNo == soleNum); if (res != null) { for (int i = 0; i < res.Count; i++) { res[i].ProCode = procode; _repository.Update(res[i]); } WriteCSV_Bind(procode, soleNum, proName, Order); } } #region 相同部分 public void TestRes(string sp, string result, string opname) { var res = _repository.GetFirstDefault<Information>(c => c.ProCode == sp && c.OperatorCode == opname); if (res == null) { if (Order != null) { Application.Current.Dispatcher.Invoke(new Action(() => { var productNew = new InformationNew { OperatorCode = opname, ItemCode = "", SpendTime = 0, CreateTime = DateTime.Today, ProType = proName, ProNo = "", ProCode = sp, OrderNo = Order, TestResult = result }; var product = new Information() { CreateTime = productNew.CreateTime, Id = Guid.NewGuid(), OperatorCode = productNew.OperatorCode, ItemCode = productNew.ItemCode, SpendTime = productNew.SpendTime, ProType = productNew.ProType, ProNo = productNew.ProNo, ProCode = productNew.ProCode, OrderNo = productNew.OrderNo, TestResult = productNew.TestResult }; InforNew.Add(productNew); _repository.Add(product); })); if (result == "OK") { try { var list = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);//查一个值 if (list != null) { list.OkS++; _repository.Update(list); } var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == DateTime.Today); if (allnumbers != null) { allnumbers.OkA++; _repository.Update(allnumbers); } } catch (Exception ex) { WriteLog("TEST1:" + ex.Message, LogType.Error); } } else { try { var list = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);//查一个值 if (list != null) { list.NgS++; _repository.Update(list); } var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == DateTime.Today); if (allnumbers != null) { allnumbers.NgA++; _repository.Update(allnumbers); } } catch (Exception ex) { WriteLog("TEST2:" + ex.Message, LogType.Error); } } } //else //{ WriteLog("订单编号没有设置", LogType.Warning); } } else { if (result == "OK") { var inf = _repository.GetFirstDefault<Information>(c => c.ProCode == sp && c.OperatorCode == opname && c.TestResult == "OK"); if (inf == null) { try { var list = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);//查一个值 if (list != null) { list.OkS++; list.NgS--; _repository.Update(list); } var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == DateTime.Today); if (allnumbers != null) { allnumbers.OkA++; allnumbers.NgA--; _repository.Update(allnumbers); } res.TestResult = result; _repository.Update(res); } catch (Exception ex) { WriteLog("TEST3:" + ex.Message, LogType.Error); } } } else { var inf = _repository.GetFirstDefault<Information>(c => c.ProCode == sp && c.OperatorCode == opname && c.TestResult == "NG"); if (inf == null) { try { var list = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);//查一个值 if (list != null) { list.NgS++; list.OkS--; _repository.Update(list); } var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == DateTime.Today); if (allnumbers != null) { allnumbers.NgA++; allnumbers.OkA--; _repository.Update(allnumbers); } res.TestResult = result; _repository.Update(res); } catch (Exception ex) { WriteLog("TEST4:" + ex.Message, LogType.Error); } } } } } #endregion bool mybool = false; private async void _timer_Elapsed1() { while (true) { try { if (Connected) { if (tcpNet.ReadInt(1500) == 1) { tcpNet.WriteInt(1500, 0); } } } catch (Exception ex) { WriteLog("Timer:" + ex.Message, LogType.Error); } await Task.Delay(1000); } } public void ProcessFinish(object sender, StateEventArgs e) { try { var list = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);//查一个值 if (list != null) { list.RealityS++; _repository.Update(list); } var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == DateTime.Today); //if (allnumbers != null) //{ allnumbers.RealityA++; _repository.Update(allnumbers); //} var d1 = tcpNet.ReadInt(1090); var d2 = tcpNet.ReadInt(1091); var d3 = tcpNet.ReadInt(1092); soleNum = d1.ToString() + d2.ToString() + d3.ToString(); Quest(Order); tcpNet.Write("1026.4", false); } catch (Exception ex) { WriteLog("ProcessFinish:" + ex.Message, LogType.Error); } } string plannum; double plan; List<string> fbarcode = new List<string>(); private void OrderEnter() { try { fbarcode.Clear(); Quest(Order); var customRepo = new CustomRepository(); try { var list = customRepo.GetFirstDefault<ICMO>(c => c.FBillNo == Order); if (list != null) { plannum = list.FAuxQty.ToString(); plan = Math.Round(Convert.ToDouble(plannum)); WriteLog("切换订单成功"); try { var ps = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order); if (ps == null) { var outp = new ProStatus() { Id = Guid.NewGuid(), OrdNoS = Order, PlanS = plan, RealityS = 0, OkS = 0, NgS = 0, ErrS = 0 }; _repository.Add(outp); // //打印产品码 var t_pda = customRepo.GetAllQuery<t_PDABarCodeSign>(c => c.FBillNo == Order); if (t_pda != null) { for (int i = 0; i < t_pda.Count; i++) { fbarcode.Add(t_pda[i].FBarCode); tcpService.Send("192.168.10.15", "print:" + fbarcode[i]); } } // var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == DateTime.Today); if (allnumbers != null) { allnumbers.PlanA = allnumbers.PlanA + plan; _repository.Update(allnumbers); } else { var al = new AllNumber() { Id = Guid.NewGuid(), DateA = DateTime.Today, PlanA = plan, RealityA = 0, OkA = 0, NgA = 0, ErrA = 0 }; _repository.Add(al); } } } catch (Exception ex) { WriteLog("OrderEnter2:" + ex.Message, LogType.Error); } } else { WriteLog("订单错误", LogType.Error); } } catch (Exception ex) { WriteLog("OrderEnter1:" + ex.Message, LogType.Error); } } catch (Exception ex) { WriteLog("OrderEnter3:" + ex.Message, LogType.Error); } } //public void ReadOrder() //{ // var customRepo = new CustomRepository(); // try // { // DateTime max = DateTime.Today.AddDays(1); // DateTime min = DateTime.Today.AddDays(-1); // //var list = customRepo.GetAllQuery<ICMO>(c => c.FDate == DateTime.Today); // var list = customRepo.GetAllQuery<ICMO>(c => c.FDate < max && c.FDate > min); // if (list != null) // { // OrderNames = new ObservableCollection<string>(); // for (int i = 0; i < list.Count; i++) // { // OrderNames.Add(list[i].FBillNo); // } // } // } // catch (Exception ex) // { // WriteLog("ReadOrder:" + ex.Message, LogType.Error); // } //} private void UploadOutWork() { var list = _repository.GetFirstDefault<OutofWork>(c => c.DateOutWork == DateTime.Today); if (list != null) { list.DateOutWork = DateTime.Today; list.Actual = ActPer; list.FallIll = FallPer; list.Absenteeism = AbsPer; _repository.Update(list); WriteLog("出勤信息上传成功"); } else { var outwork = new OutofWork() { Id = Guid.NewGuid(), DateOutWork = DateTime.Today, Actual = ActPer, FallIll = FallPer, Absenteeism = AbsPer, }; _repository.Add(outwork); WriteLog("出勤信息上传成功"); } } private void UploadHouse() { var list = _repository.GetFirstDefault<House>(c => c.DateH == DateTime.Today); if (list != null) { list.DateH = DateTime.Today; list.LackH = LackHouse; list.UsedH = UsedHouse; list.TotalH = TotalHouse; _repository.Update(list); WriteLog("线边仓数据上传成功"); } else { var houses = new House() { Id = Guid.NewGuid(), DateH = DateTime.Today, LackH = LackHouse, UsedH = UsedHouse, TotalH = TotalHouse, }; _repository.Add(houses); WriteLog("线边仓数据上传成功"); } } //void SwitchProduct() //{ // SendToClient("Num1"); //} //public void SendToClient(string id) //{ // //tcpService.SocketClients.GetIds() 向所有id发送 // //foreach (var item in tcpService.SocketClients.GetIds()) // //{ // // if (string.IsNullOrWhiteSpace(SelectedConfigName)) // // { // // tcpService.Send(item, "None"); // // WriteLog("发送:None"); // // return; // // } // // tcpService.Send(item, SelectedConfigName); // // WriteLog("发送:" + SelectedConfigName); // //} // if (string.IsNullOrWhiteSpace(SelectedConfigName)) // { // tcpService.Send(id, "None"); // WriteLog("发送:None"); // return; // } // tcpService.Send(id, SelectedConfigName); // WriteLog("发送:" + SelectedConfigName); //} public void SendPro(string id, string name) { try { var ids = tcpService.SocketClients.GetIds(); foreach (var item in tcpService.SocketClients.GetClients()) { if (item.IP == id) { item.Send("Type:" + name + ":" + id); WriteLog("发送:" + name); break; } } //tcpService.Send(id, "Type:" + name + ":" + id); //WriteLog("发送:" + name); } catch (Exception ex) { WriteLog("SendPro:" + ex.Message, LogType.Error); } } string p1 = null, p2 = null, p3 = null, p4 = null, p5 = null, p6 = null, p7 = null, p8 = null, p9 = null, p10 = null, p11 = null, p12 = null, p13 = null, p14 = null; #region 工位 public void RecordOneMessage1(object sender, StateEventArgs e)//1 { Application.Current.Dispatcher.Invoke(new Action(() => { if (Order != null) { _logger.Information("{@Message}", "工位1触发"); //for (int i = 0; i < listMaterial1.Count; i++) //{ // if (i == 0) // { // Material1 = listMaterial1[0]; // } // else // { // Material1 = Material1 + "," + listMaterial1[i]; // } //} var spt = tcpNet.ReadInt(1003); var d1 = tcpNet.ReadInt(1030); var d2 = tcpNet.ReadInt(1031); var d3 = tcpNet.ReadInt(1032); var pno = d1.ToString() + d2.ToString() + d3.ToString(); _logger.Information("{@Message}", $"工位1_pno{pno}"); if (pno != p1) { var productNew = new InformationNew { OperatorCode = Operator1, ItemCode = Material1, SpendTime = spt / 10, CreateTime = DateTime.Today, ProType = proName, ProNo = pno, ProCode = "", OrderNo = Order, TestResult = "" }; var product = new Information() { CreateTime = productNew.CreateTime, Id = Guid.NewGuid(), OperatorCode = productNew.OperatorCode, ItemCode = productNew.ItemCode, SpendTime = productNew.SpendTime, ProType = productNew.ProType, ProNo = productNew.ProNo, ProCode = productNew.ProCode, OrderNo = productNew.OrderNo, TestResult = productNew.TestResult }; WriteCSV_Pro(Operator1, pno, proName, Order, Material1); InforNew.Add(productNew); _repository.Add(product); OperatorName(operName); _logger.Information("{@Message}", $"工位1_Add"); //listMaterial1.Clear(); } p1 = d1.ToString() + d2.ToString() + d3.ToString(); Thread.Sleep(200); tcpNet.Write("1025.0", false); _logger.Information("{@Message}", $"工位1_writefalse2"); } tcpNet.Write("1025.0", false); _logger.Information("{@Message}", $"工位1_writefalse3"); })); } public void RecordOneMessage2(object sender, StateEventArgs e)//2 { Application.Current.Dispatcher.Invoke(new Action(() => { if (Order != null) { _logger.Information("{@Message}", "工位2触发"); var spt = tcpNet.ReadInt(1004); var d1 = tcpNet.ReadInt(1033); var d2 = tcpNet.ReadInt(1034); var d3 = tcpNet.ReadInt(1035); var pno = d1.ToString() + d2.ToString() + d3.ToString(); _logger.Information("{@Message}", $"工位2_pno{pno}"); if (pno != p2) { var productNew = new InformationNew { OperatorCode = Operator2, ItemCode = Material2, SpendTime = spt / 10, CreateTime = DateTime.Today, ProType = proName, ProNo = pno, ProCode = "", OrderNo = Order, TestResult = "" }; var product = new Information() { CreateTime = productNew.CreateTime, Id = Guid.NewGuid(), OperatorCode = productNew.OperatorCode, ItemCode = productNew.ItemCode, SpendTime = productNew.SpendTime, ProType = productNew.ProType, ProNo = productNew.ProNo, ProCode = productNew.ProCode, OrderNo = productNew.OrderNo, TestResult = productNew.TestResult }; WriteCSV_Pro(Operator2, pno, proName, Order, Material2); _repository.Add(product); InforNew.Add(productNew); OperatorName(operName); _logger.Information("{@Message}", $"工位2_Add"); } p2 = d1.ToString() + d2.ToString() + d3.ToString(); Thread.Sleep(200); tcpNet.Write("1025.1", false); _logger.Information("{@Message}", $"工位2_writefalse2"); } tcpNet.Write("1025.1", false); _logger.Information("{@Message}", $"工位2_writefalse3"); })); } public void RecordOneMessage3(object sender, StateEventArgs e)//3 { Application.Current.Dispatcher.Invoke(new Action(() => { if (Order != null) { _logger.Information("{@Message}", "工位3触发"); var spt = tcpNet.ReadInt(1005); var d1 = tcpNet.ReadInt(1036); var d2 = tcpNet.ReadInt(1037); var d3 = tcpNet.ReadInt(1038); var pno = d1.ToString() + d2.ToString() + d3.ToString(); _logger.Information("{@Message}", $"工位3_pno{pno}"); if (pno != p3) { var productNew = new InformationNew { OperatorCode = Operator3, ItemCode = Material3, SpendTime = spt / 10, CreateTime = DateTime.Today, ProType = proName, ProNo = pno, ProCode = "", OrderNo = Order, TestResult = "" }; var product = new Information() { CreateTime = productNew.CreateTime, Id = Guid.NewGuid(), OperatorCode = productNew.OperatorCode, ItemCode = productNew.ItemCode, SpendTime = productNew.SpendTime, ProType = productNew.ProType, ProNo = productNew.ProNo, ProCode = productNew.ProCode, OrderNo = productNew.OrderNo, TestResult = productNew.TestResult }; WriteCSV_Pro(Operator3, pno, proName, Order, Material3); _repository.Add(product); InforNew.Add(productNew); OperatorName(operName); _logger.Information("{@Message}", $"工位3_Add"); } p3 = d1.ToString() + d2.ToString() + d3.ToString(); Thread.Sleep(200); tcpNet.Write("1025.2", false); _logger.Information("{@Message}", $"工位3_writefalse2"); } tcpNet.Write("1025.2", false); _logger.Information("{@Message}", $"工位3_writefalse3"); })); } public void RecordOneMessage4(object sender, StateEventArgs e)//4 { Application.Current.Dispatcher.Invoke(new Action(() => { if (Order != null) { _logger.Information("{@Message}", "工位4触发"); var spt = tcpNet.ReadInt(1006); var d1 = tcpNet.ReadInt(1039); var d2 = tcpNet.ReadInt(1040); var d3 = tcpNet.ReadInt(1041); var pno = d1.ToString() + d2.ToString() + d3.ToString(); _logger.Information("{@Message}", $"工位4_pno{pno}"); if (pno != p4) { var productNew = new InformationNew { OperatorCode = Operator4, ItemCode = Material4, SpendTime = spt / 10, CreateTime = DateTime.Today, ProType = proName, ProNo = pno, ProCode = "", OrderNo = Order, TestResult = "" }; var product = new Information() { CreateTime = productNew.CreateTime, Id = Guid.NewGuid(), OperatorCode = productNew.OperatorCode, ItemCode = productNew.ItemCode, SpendTime = productNew.SpendTime, ProType = productNew.ProType, ProNo = productNew.ProNo, ProCode = productNew.ProCode, OrderNo = productNew.OrderNo, TestResult = productNew.TestResult }; WriteCSV_Pro(Operator4, pno, proName, Order, Material4); _repository.Add(product); InforNew.Add(productNew); OperatorName(operName); _logger.Information("{@Message}", $"工位4_Add"); } p4 = d1.ToString() + d2.ToString() + d3.ToString(); Thread.Sleep(200); tcpNet.Write("1025.3", false); _logger.Information("{@Message}", $"工位4_writefalse2"); } tcpNet.Write("1025.3", false); _logger.Information("{@Message}", $"工位4_writefalse3"); })); } public void RecordOneMessage5(object sender, StateEventArgs e)//5 { Application.Current.Dispatcher.Invoke(new Action(() => { if (Order != null) { _logger.Information("{@Message}", "工位5触发"); var spt = tcpNet.ReadInt(1007); var d1 = tcpNet.ReadInt(1042); var d2 = tcpNet.ReadInt(1043); var d3 = tcpNet.ReadInt(1044); var pno = d1.ToString() + d2.ToString() + d3.ToString(); _logger.Information("{@Message}", $"工位5_pno{pno}"); if (pno != p5) { var productNew = new InformationNew { OperatorCode = Operator5, ItemCode = Material5, SpendTime = spt / 10, CreateTime = DateTime.Today, ProType = proName, ProNo = pno, ProCode = "", OrderNo = Order, TestResult = "" }; var product = new Information() { CreateTime = productNew.CreateTime, Id = Guid.NewGuid(), OperatorCode = productNew.OperatorCode, ItemCode = productNew.ItemCode, SpendTime = productNew.SpendTime, ProType = productNew.ProType, ProNo = productNew.ProNo, ProCode = productNew.ProCode, OrderNo = productNew.OrderNo, TestResult = productNew.TestResult }; WriteCSV_Pro(Operator5, pno, proName, Order, Material5); _repository.Add(product); InforNew.Add(productNew); OperatorName(operName); _logger.Information("{@Message}", $"工位5_Add"); } p5 = d1.ToString() + d2.ToString() + d3.ToString(); Thread.Sleep(200); tcpNet.Write("1025.4", false); _logger.Information("{@Message}", $"工位5_writefalse2"); } tcpNet.Write("1025.4", false); _logger.Information("{@Message}", $"工位5_writefalse3"); })); } public void RecordOneMessage6(object sender, StateEventArgs e)//6 { Application.Current.Dispatcher.Invoke(new Action(() => { if (Order != null) { _logger.Information("{@Message}", "工位6触发"); var spt = tcpNet.ReadInt(1008); var d1 = tcpNet.ReadInt(1045); var d2 = tcpNet.ReadInt(1046); var d3 = tcpNet.ReadInt(1047); var pno = d1.ToString() + d2.ToString() + d3.ToString(); _logger.Information("{@Message}", $"工位6_pno{pno}"); if (pno != p6) { var productNew = new InformationNew { OperatorCode = Operator6, ItemCode = Material6, SpendTime = spt / 10, CreateTime = DateTime.Today, ProType = proName, ProNo = pno, ProCode = "", OrderNo = Order, TestResult = "" }; var product = new Information() { CreateTime = productNew.CreateTime, Id = Guid.NewGuid(), OperatorCode = productNew.OperatorCode, ItemCode = productNew.ItemCode, SpendTime = productNew.SpendTime, ProType = productNew.ProType, ProNo = productNew.ProNo, ProCode = productNew.ProCode, OrderNo = productNew.OrderNo, TestResult = productNew.TestResult }; WriteCSV_Pro(Operator6, pno, proName, Order, Material6); _repository.Add(product); InforNew.Add(productNew); OperatorName(operName); _logger.Information("{@Message}", $"工位6_Add"); } p6 = d1.ToString() + d2.ToString() + d3.ToString(); Thread.Sleep(200); tcpNet.Write("1025.5", false); _logger.Information("{@Message}", $"工位6_writefalse2"); } tcpNet.Write("1025.5", false); _logger.Information("{@Message}", $"工位6_writefalse3"); })); } public void RecordOneMessage7(object sender, StateEventArgs e)//7 { Application.Current.Dispatcher.Invoke(new Action(() => { if (Order != null) { _logger.Information("{@Message}", "工位7触发"); var spt = tcpNet.ReadInt(1011); var d1 = tcpNet.ReadInt(1048); var d2 = tcpNet.ReadInt(1049); var d3 = tcpNet.ReadInt(1050); var pno = d1.ToString() + d2.ToString() + d3.ToString(); _logger.Information("{@Message}", $"工位7_pno{pno}"); if (pno != p7) { var productNew = new InformationNew { OperatorCode = Operator7, ItemCode = Material7, SpendTime = spt / 10, CreateTime = DateTime.Today, ProType = proName, ProNo = pno, ProCode = "", OrderNo = Order, TestResult = "" }; var product = new Information() { CreateTime = productNew.CreateTime, Id = Guid.NewGuid(), OperatorCode = productNew.OperatorCode, ItemCode = productNew.ItemCode, SpendTime = productNew.SpendTime, ProType = productNew.ProType, ProNo = productNew.ProNo, ProCode = productNew.ProCode, OrderNo = productNew.OrderNo, TestResult = productNew.TestResult }; WriteCSV_Pro(Operator7, pno, proName, Order, Material7); _repository.Add(product); InforNew.Add(productNew); OperatorName(operName); _logger.Information("{@Message}", $"工位7_Add"); } p7 = d1.ToString() + d2.ToString() + d3.ToString(); Thread.Sleep(200); tcpNet.Write("1025.8", false); _logger.Information("{@Message}", $"工位7_writefalse2"); } tcpNet.Write("1025.8", false); _logger.Information("{@Message}", $"工位7_writefalse3"); })); } public void RecordOneMessage8(object sender, StateEventArgs e)//8 { Application.Current.Dispatcher.Invoke(new Action(() => { if (Order != null) { _logger.Information("{@Message}", "工位8触发"); var spt = tcpNet.ReadInt(1012); var d1 = tcpNet.ReadInt(1051); var d2 = tcpNet.ReadInt(1052); var d3 = tcpNet.ReadInt(1053); var pno = d1.ToString() + d2.ToString() + d3.ToString(); _logger.Information("{@Message}", $"工位8_pno{pno}"); if (pno != p8) { var productNew = new InformationNew { OperatorCode = Operator8, ItemCode = Material8, SpendTime = spt / 10, CreateTime = DateTime.Today, ProType = proName, ProNo = pno, ProCode = "", OrderNo = Order, TestResult = "" }; var product = new Information() { CreateTime = productNew.CreateTime, Id = Guid.NewGuid(), OperatorCode = productNew.OperatorCode, ItemCode = productNew.ItemCode, SpendTime = productNew.SpendTime, ProType = productNew.ProType, ProNo = productNew.ProNo, ProCode = productNew.ProCode, OrderNo = productNew.OrderNo, TestResult = productNew.TestResult }; WriteCSV_Pro(Operator8, pno, proName, Order, Material8); _repository.Add(product); InforNew.Add(productNew); OperatorName(operName); _logger.Information("{@Message}", $"工位8_Add"); } p8 = d1.ToString() + d2.ToString() + d3.ToString(); Thread.Sleep(200); tcpNet.Write("1025.9", false); _logger.Information("{@Message}", $"工位8_writefalse2"); } tcpNet.Write("1025.9", false); _logger.Information("{@Message}", $"工位8_writefalse3"); })); } public void RecordOneMessage9(object sender, StateEventArgs e)//9 { Application.Current.Dispatcher.Invoke(new Action(() => { if (Order != null) { _logger.Information("{@Message}", "工位9触发"); var spt = tcpNet.ReadInt(1013); var d1 = tcpNet.ReadInt(1054); var d2 = tcpNet.ReadInt(1055); var d3 = tcpNet.ReadInt(1056); var pno = d1.ToString() + d2.ToString() + d3.ToString(); _logger.Information("{@Message}", $"工位9_pno{pno}"); if (pno != p9) { var productNew = new InformationNew { OperatorCode = Operator9, ItemCode = Material9, SpendTime = spt / 10, CreateTime = DateTime.Today, ProType = proName, ProNo = pno, ProCode = "", OrderNo = Order, TestResult = "" }; var product = new Information() { CreateTime = productNew.CreateTime, Id = Guid.NewGuid(), OperatorCode = productNew.OperatorCode, ItemCode = productNew.ItemCode, SpendTime = productNew.SpendTime, ProType = productNew.ProType, ProNo = productNew.ProNo, ProCode = productNew.ProCode, OrderNo = productNew.OrderNo, TestResult = productNew.TestResult }; WriteCSV_Pro(Operator9, pno, proName, Order, Material9); _repository.Add(product); InforNew.Add(productNew); OperatorName(operName); _logger.Information("{@Message}", $"工位9_Add"); } p9 = d1.ToString() + d2.ToString() + d3.ToString(); Thread.Sleep(200); tcpNet.Write("1025.10", false); _logger.Information("{@Message}", $"工位9_writefalse2"); } tcpNet.Write("1025.10", false); _logger.Information("{@Message}", $"工位9_writefalse3"); })); } public void RecordOneMessage10(object sender, StateEventArgs e)//10 { Application.Current.Dispatcher.Invoke(new Action(() => { if (Order != null) { _logger.Information("{@Message}", "工位10触发"); var spt = tcpNet.ReadInt(1014); var d1 = tcpNet.ReadInt(1057); var d2 = tcpNet.ReadInt(1058); var d3 = tcpNet.ReadInt(1059); var pno = d1.ToString() + d2.ToString() + d3.ToString(); _logger.Information("{@Message}", $"工位10_pno{pno}"); if (pno != p10) { var productNew = new InformationNew { OperatorCode = Operator10, ItemCode = Material10, SpendTime = spt / 10, CreateTime = DateTime.Today, ProType = proName, ProNo = pno, ProCode = "", OrderNo = Order, TestResult = "" }; var product = new Information() { CreateTime = productNew.CreateTime, Id = Guid.NewGuid(), OperatorCode = productNew.OperatorCode, ItemCode = productNew.ItemCode, SpendTime = productNew.SpendTime, ProType = productNew.ProType, ProNo = productNew.ProNo, ProCode = productNew.ProCode, OrderNo = productNew.OrderNo, TestResult = productNew.TestResult }; WriteCSV_Pro(Operator10, pno, proName, Order, Material10); _repository.Add(product); InforNew.Add(productNew); OperatorName(operName); _logger.Information("{@Message}", $"工位10_Add"); } p10 = d1.ToString() + d2.ToString() + d3.ToString(); Thread.Sleep(200); tcpNet.Write("1025.11", false); _logger.Information("{@Message}", $"工位10_writefalse2"); } tcpNet.Write("1025.11", false); _logger.Information("{@Message}", $"工位10_writefalse3"); })); } public void RecordOneMessage11(object sender, StateEventArgs e)//11 { Application.Current.Dispatcher.Invoke(new Action(() => { if (Order != null) { _logger.Information("{@Message}", "工位11触发"); var spt = tcpNet.ReadInt(1017); var d1 = tcpNet.ReadInt(1060); var d2 = tcpNet.ReadInt(1061); var d3 = tcpNet.ReadInt(1062); var pno = d1.ToString() + d2.ToString() + d3.ToString(); _logger.Information("{@Message}", $"工位11_pno{pno}"); if (pno != p11) { var productNew = new InformationNew { OperatorCode = Operator11, ItemCode = Material11, SpendTime = spt / 10, CreateTime = DateTime.Today, ProType = proName, ProNo = pno, ProCode = "", OrderNo = Order, TestResult = "" }; var product = new Information() { CreateTime = productNew.CreateTime, Id = Guid.NewGuid(), OperatorCode = productNew.OperatorCode, ItemCode = productNew.ItemCode, SpendTime = productNew.SpendTime, ProType = productNew.ProType, ProNo = productNew.ProNo, ProCode = productNew.ProCode, OrderNo = productNew.OrderNo, TestResult = productNew.TestResult }; WriteCSV_Pro(Operator11, pno, proName, Order, Material11); _repository.Add(product); InforNew.Add(productNew); OperatorName(operName); _logger.Information("{@Message}", $"工位11_Add"); } p11 = d1.ToString() + d2.ToString() + d3.ToString(); Thread.Sleep(200); tcpNet.Write("1025.14", false); _logger.Information("{@Message}", $"工位11_writefalse2"); } tcpNet.Write("1025.14", false); _logger.Information("{@Message}", $"工位11_writefalse3"); })); } public void RecordOneMessage12(object sender, StateEventArgs e)//12 { Application.Current.Dispatcher.Invoke(new Action(() => { if (Order != null) { _logger.Information("{@Message}", "工位12触发"); var spt = tcpNet.ReadInt(1018); var d1 = tcpNet.ReadInt(1063); var d2 = tcpNet.ReadInt(1064); var d3 = tcpNet.ReadInt(1065); var pno = d1.ToString() + d2.ToString() + d3.ToString(); _logger.Information("{@Message}", $"工位12_pno{pno}"); if (pno != p12) { var productNew = new InformationNew { OperatorCode = Operator12, ItemCode = Material12, SpendTime = spt / 10, CreateTime = DateTime.Today, ProType = proName, ProNo = pno, ProCode = "", OrderNo = Order, TestResult = "" }; var product = new Information() { CreateTime = productNew.CreateTime, Id = Guid.NewGuid(), OperatorCode = productNew.OperatorCode, ItemCode = productNew.ItemCode, SpendTime = productNew.SpendTime, ProType = productNew.ProType, ProNo = productNew.ProNo, ProCode = productNew.ProCode, OrderNo = productNew.OrderNo, TestResult = productNew.TestResult }; WriteCSV_Pro(Operator12, pno, proName, Order, Material12); _repository.Add(product); InforNew.Add(productNew); OperatorName(operName); _logger.Information("{@Message}", $"工位12_Add"); } p12 = d1.ToString() + d2.ToString() + d3.ToString(); Thread.Sleep(200); tcpNet.Write("1025.15", false); _logger.Information("{@Message}", $"工位12_writefalse2"); } tcpNet.Write("1025.15", false); _logger.Information("{@Message}", $"工位12_writefalse3"); })); } public void RecordOneMessage13(object sender, StateEventArgs e)//13 { Application.Current.Dispatcher.Invoke(new Action(() => { if (Order != null) { _logger.Information("{@Message}", "工位13触发"); var spt = tcpNet.ReadInt(1019); var d1 = tcpNet.ReadInt(1066); var d2 = tcpNet.ReadInt(1067); var d3 = tcpNet.ReadInt(1068); var pno = d1.ToString() + d2.ToString() + d3.ToString(); _logger.Information("{@Message}", $"工位13_pno{pno}"); if (pno != p13) { var productNew = new InformationNew { OperatorCode = Operator13, ItemCode = Material13, SpendTime = spt / 10, CreateTime = DateTime.Today, ProType = proName, ProNo = pno, ProCode = "", OrderNo = Order, TestResult = "" }; var product = new Information() { CreateTime = productNew.CreateTime, Id = Guid.NewGuid(), OperatorCode = productNew.OperatorCode, ItemCode = productNew.ItemCode, SpendTime = productNew.SpendTime, ProType = productNew.ProType, ProNo = productNew.ProNo, ProCode = productNew.ProCode, OrderNo = productNew.OrderNo, TestResult = productNew.TestResult }; WriteCSV_Pro(Operator13, pno, proName, Order, Material13); _repository.Add(product); InforNew.Add(productNew); OperatorName(operName); _logger.Information("{@Message}", $"工位13_Add"); } p13 = d1.ToString() + d2.ToString() + d3.ToString(); Thread.Sleep(200); tcpNet.Write("1026.0", false); _logger.Information("{@Message}", $"工位13_writefalse2"); } tcpNet.Write("1026.0", false); _logger.Information("{@Message}", $"工位13_writefalse3"); })); } public void RecordOneMessage14(object sender, StateEventArgs e)//14 { Application.Current.Dispatcher.Invoke(new Action(() => { try { if (Order != null) { _logger.Information("{@Message}", "工位14触发"); var spt = tcpNet.ReadInt(1020); var d1 = tcpNet.ReadInt(1069); var d2 = tcpNet.ReadInt(1070); var d3 = tcpNet.ReadInt(1071); var pno = d1.ToString() + d2.ToString() + d3.ToString(); _logger.Information("{@Message}", $"工位14_pno{pno}"); if (pno != p14) { var productNew = new InformationNew { OperatorCode = Operator14, ItemCode = Material14, SpendTime = spt / 10, CreateTime = DateTime.Today, ProType = proName, ProNo = pno, ProCode = "", OrderNo = Order, TestResult = "" }; var product = new Information() { CreateTime = productNew.CreateTime, Id = Guid.NewGuid(), OperatorCode = productNew.OperatorCode, ItemCode = productNew.ItemCode, SpendTime = productNew.SpendTime, ProType = productNew.ProType, ProNo = productNew.ProNo, ProCode = productNew.ProCode, OrderNo = productNew.OrderNo, TestResult = productNew.TestResult }; WriteCSV_Pro(Operator14, pno, proName, Order, Material14); _repository.Add(product); InforNew.Add(productNew); OperatorName(operName); _logger.Information("{@Message}", $"工位14_Add"); } p14 = d1.ToString() + d2.ToString() + d3.ToString(); Thread.Sleep(200); tcpNet.Write("1026.1", false); _logger.Information("{@Message}", $"工位14_writefalse2"); } tcpNet.Write("1026.1", false); _logger.Information("{@Message}", $"工位14_writefalse3"); } catch (Exception ex) { WriteLog("RecordOneMessage14:" + ex.Message, LogType.Error); } })); } #endregion public void OperatorName(string[] liststr) { _eventAggregator.GetEvent<OperatorNameEvent>().Publish(liststr); } public void Quest(string str) { _eventAggregator.GetEvent<QuestEvent>().Publish(str); } public void Alarm(Dictionary<string, string> plcsignal) { _eventAggregator.GetEvent<AlarmEvent>().Publish(plcsignal);//跨viewmodel发信息,Publish(发送的消息) } bool one = true; string proName; private void Timer_Elapsed() { while (true) { if (!Connected) { if (one) { WriteLog("plc连接异常", LogType.Error); one = false; } continue; } try { if (one) { WriteLog("plc连接成功", LogType.Info); one = false; } foreach (var item in SignalMapper) { //if (e.StartingAddress+e.Points.Length < item.Value) //{ // continue; //} //var data = e.Points[item.Value]; //var value = inovanceTcp.Read(item.Value, 1); var value = tcpNet.ReadBool(item.Value); _stateService.ExecuteState(item.Key, value ? (ushort)1 : (ushort)0); } } catch (ObjectDisposedException ex) { WriteLog("Timer_Elapsed:" + ex.Message, LogType.Error); } finally { Thread.Sleep(500); } } } int a = 0; bool b = true; DateTime alarmtime; private void Timer_Elapsed2() { while (true) { if (!Connected) { continue; } try { #region 报警 if (tcpNet.ReadInt(1130) != 0 || tcpNet.ReadInt(1131) != 0) { if (b) { alarmtime = DateTime.Now; b = false; } } else { try { if (!b) { string at = GetTime(alarmtime); b = true; var list = _repository.GetFirstDefault<DeviceStatus>(c => c.DateDS == DateTime.Today); if (list != null) { list.AlarmTime = Convert.ToDouble(at); _repository.Update(list); } else { var altime = new DeviceStatus() { Id = Guid.NewGuid(), DateDS = DateTime.Today, AlarmTime = Convert.ToDouble(at) }; _repository.Add(altime); } } } catch (Exception) { } } var dictionary = new Dictionary<string, string>(); for (int i = 0; i < 31; i++) { var addrress = 1100 + i; int ad = tcpNet.ReadInt((ushort)addrress); if (ad != 0 && ad != -1) { dictionary.Add(addrress.ToString(), "报警"); } else { dictionary.Add(addrress.ToString(), "正常"); } } for (int i = 0; i < 25; i++) { var addrress = (1141.15 + i).ToString(); if (tcpNet.ReadBool(addrress)) { dictionary.Add(addrress, "缺料"); } else { dictionary.Add(addrress, "正常"); } } for (int i = 0; i < 7; i++) { var addrress = (1166 + (double)i / 10).ToString("0.0"); if (tcpNet.ReadBool(addrress)) { dictionary.Add(addrress, "缺料"); } else { dictionary.Add(addrress, "正常"); } } Alarm(dictionary); #endregion } catch (ObjectDisposedException ex) { WriteLog("Timer_Elapsed2:" + ex.Message, LogType.Error); } finally { Thread.Sleep(1000); } } } private void Timer_Elapsed3() { while (true) { if (!Connected) { continue; } try { //ReadOrder(); //切换产品 int type = tcpNet.ReadInt(1000); if (a != type && type != -1) { Change(); } if (type != -1) { a = type; } } catch (ObjectDisposedException ex) { WriteLog("Timer_Elapsed3:" + ex.Message, LogType.Error); } finally { Thread.Sleep(1000); } } } //时间差 public static string GetTime(DateTime timeA) { //timeA 表示需要计算 DateTime timeB = DateTime.Now; //获取当前时间 TimeSpan ts = timeB - timeA; //计算时间差 string time = ts.TotalMinutes.ToString("0.00"); //将时间差转换为分钟 return time; } public void Change() { int type = tcpNet.ReadInt(1000); switch (type) { case 1: proName = "P60"; break; case 2: proName = "P70"; break; case 3: proName = "P80"; break; case 4: proName = "P90"; break; case 5: proName = "T29"; break; case 6: proName = "DH-88"; break; case 7: proName = "QL-1"; break; } if (tcpNet.ReadBool("1001.0")) { SendPro("192.168.10.1", proName); } if (tcpNet.ReadBool("1001.1")) { SendPro("192.168.10.2", proName); } if (tcpNet.ReadBool("1001.2")) { SendPro("192.168.10.3", proName); } if (tcpNet.ReadBool("1001.3")) { SendPro("192.168.10.4", proName); } if (tcpNet.ReadBool("1001.4")) { SendPro("192.168.10.5", proName); } if (tcpNet.ReadBool("1001.5")) { SendPro("192.168.10.6", proName); } if (tcpNet.ReadBool("1001.6")) { SendPro("192.168.10.7", proName); } if (tcpNet.ReadBool("1001.7")) { SendPro("192.168.10.8", proName); } if (tcpNet.ReadBool("1001.8")) { SendPro("192.168.10.9", proName); } if (tcpNet.ReadBool("1001.9")) { SendPro("192.168.10.10", proName); } if (tcpNet.ReadBool("1001.10")) { SendPro("192.168.10.11", proName); } if (tcpNet.ReadBool("1001.11")) { SendPro("192.168.10.12", proName); } if (tcpNet.ReadBool("1001.12")) { SendPro("192.168.10.13", proName); } if (tcpNet.ReadBool("1001.13")) { SendPro("192.168.10.14", proName); } if (tcpNet.ReadBool("1001.14")) { SendPro("192.168.10.15", proName); } if (tcpNet.ReadBool("1001.15")) { SendPro("192.168.10.16", proName); } if (tcpNet.ReadBool("1002.0")) { SendPro("192.168.10.17", proName); } if (tcpNet.ReadBool("1002.1")) { SendPro("192.168.10.18", proName); } } public string SelectedConfigName { get; set; } public ObservableCollection<string> ConfigNames { get; set; } public WriteableBitmap QrImage { get; set; } public void ReadConfig() { ConfigNames = new ObservableCollection<string>(); if (!Directory.Exists(@"d:\作业指导书\")) { return; } var files = Directory.GetFiles(@"d:\作业指导书\"); foreach (var item in files) { var file = new FileInfo(item); if (file.Extension == ".json") { ConfigNames.Add(file.Name.Replace(file.Extension, "")); } } } public string ResWord(string s) { string[] str = s.Split(','); List<string> words = new List<string>(); for (int i = 0; i < str.Length; i++) { if (str[i] != "") { words.Add(str[i]); } } return string.Join(",", words.ToArray()); } #region log private void WriteLog(string message, LogType logType = LogType.Info, Exception exception = null) { if (exception != null) { _logger.Error("{@Message}", exception.ToString()); } else { _logger.Information("{@Message}", message); } string singleLine = message.Trim(); string item = $"【{DateTime.Now:F}】 {singleLine}"; _eventAggregator.GetEvent<LogEvent>().Publish(new Tuple<LogType, string>(logType, item)); } #endregion #region WriteCSV //生产信息 public void WriteCSV_Pro(string idPeople, string proNo, string proType, string order, string Wu) { string s1, s2, s3, s4, s11, s12, s13, s14, s15, s16, s21, s22, s23, s24, s25, s26; // string path = "D:\\Result\\生产信息\\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // s11 = "时间"; s12 = "人员ID"; s13 = "产品编号"; s14 = "产品类型"; s15 = "订单编号"; s16 = "物料码"; // s21 = DateTime.Now.ToString("HH:mm:ss"); s22 = idPeople; s23 = proNo; s24 = proType; s25 = order; s26 = Wu; //========================= s1 = path; s2 = DateTime.Now.ToString("yyyyMMdd"); //表格命名以天记录 s3 = s11 + "," + s12 + "," + s13; s4 = s21 + "," + s22 + "," + s23; // DataHelp.Save(s1, s2, s3, s4); } //绑定信息 public void WriteCSV_Bind(string proCode, string proNo, string proType, string order) { string s1, s2, s3, s4, s11, s12, s13, s14, s15, s21, s22, s23, s24, s25; // string path = "D:\\Result\\绑定信息\\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // s11 = "时间"; s12 = "产品码"; s13 = "产品编号"; s14 = "产品类型"; s15 = "订单编号"; // s21 = DateTime.Now.ToString("HH:mm:ss"); s22 = proCode; s23 = proNo; s24 = proType; s25 = order; //========================= s1 = path; s2 = DateTime.Now.ToString("yyyyMMdd"); //表格命名以天记录 s3 = s11 + "," + s12 + "," + s13; s4 = s21 + "," + s22 + "," + s23; // DataHelp.Save(s1, s2, s3, s4); } //检测信息 public void WriteCSV_Test(string idPeople, string proCode, string res) { string s1, s2, s3, s4, s11, s12, s13, s14, s21, s22, s23, s24; // string path = "D:\\Result\\检测信息\\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // s11 = "时间"; s12 = "检测人员ID"; s13 = "产品码"; s14 = "检测结果"; // s21 = DateTime.Now.ToString("HH:mm:ss"); s22 = idPeople; s23 = proCode; s24 = res; //========================= s1 = path; s2 = DateTime.Now.ToString("yyyyMMdd"); //表格命名以天记录 s3 = s11 + "," + s12 + "," + s13; s4 = s21 + "," + s22 + "," + s23; // DataHelp.Save(s1, s2, s3, s4); } //维修信息 public void WriteCSV_Repair(string idPeople, string proCode, string wu) { string s1, s2, s3, s4, s11, s12, s13, s14, s21, s22, s23, s24; // string path = "D:\\Result\\维修信息\\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } // s11 = "时间"; s12 = "维修人员id"; s13 = "产品码"; s14 = "维修物料"; // s21 = DateTime.Now.ToString("HH:mm:ss"); s22 = idPeople; s23 = proCode; s24 = wu; //========================= s1 = path; s2 = DateTime.Now.ToString("yyyyMMdd"); //表格命名以天记录 s3 = s11 + "," + s12 + "," + s13; s4 = s21 + "," + s22 + "," + s23; // DataHelp.Save(s1, s2, s3, s4); } #endregion #region 生成二维码 public void QRcode() { //GenerateQRCode(InQR); //GenerateBarCode(InQR, 400, 150).Save("BarCode.png", System.Drawing.Imaging.ImageFormat.Png); } /// <summary> /// 生成二维码图片 /// </summary> public void GenerateQRCode(string qrCodeContent) { if (qrCodeContent != null) { using (var generator = new QRCodeGenerator()) { // 创建二维码(并设置纠错能力最高级) var createQrCode = generator.CreateQrCode(qrCodeContent, ECCLevel.H); var skImageInfo = new SKImageInfo(300, 300); // 创建SkiaSharp画布 using (var surface = SKSurface.Create(skImageInfo)) { var canvas = surface.Canvas; // 渲染二维码到画布 canvas.Render(createQrCode, skImageInfo.Width, skImageInfo.Height); using var image = surface.Snapshot();// 获取画布快照 using var data = image.Encode(SKEncodedImageFormat.Png, 100);// 编码画布快照为PNG格式的数据 using (var stream = File.OpenWrite(@"MyQRCode.png")) { data.SaveTo(stream);// 将数据保存到文件流中,生成二维码图片 } QrImage = image.ToWriteableBitmap(); } WriteLog("二维码生成成功"); } } } /// <summary> /// 生成一维条形码 /// </summary> /// <param name="text">内容</param> /// <param name="width">宽度</param> /// <param name="height">高度</param> /// <returns></returns> public Bitmap GenerateBarCode(string text, int width, int height) { BarcodeWriter writer = new BarcodeWriter(); //使用ITF 格式,不能被现在常用的支付宝、微信扫出来 //如果想生成可识别的可以使用 CODE_128 格式 writer.Format = BarcodeFormat.CODE_128; EncodingOptions options = new EncodingOptions() { Width = width, Height = height, //GS1Format = false, //PureBarcode = true, Margin = 20 }; writer.Options = options; BitMatrix bm = writer.Encode(text); //Bitmap b = writer.Write(bm); Bitmap b = writer.Write(text); WriteLog("一维码生成成功"); return b; } #endregion } }