123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306 |
- 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;
- using HslCommunication.BasicFramework;
- using Prism.Ioc;
- using System.Linq;
- using LogoForceTestApp.Modules.MainModule.Method;
- using System.Net.Sockets;
- using System.Xml.Linq;
- 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;
- private readonly IContainerProvider _container;
- 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 SelectedClientName { get; set; }
- public ObservableCollection<string> ClientNames { 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
- private MulProductModel _Products;
- public MulProductModel Products
- {
- get { return _Products; }
- set { SetProperty(ref _Products, value); }
- }
- private CustomerInfor _Customer;
- public CustomerInfor Customer
- {
- get { return _Customer; }
- set { SetProperty(ref _Customer, value); }
- }
- 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;
- int ra;
- 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,
- IContainerProvider container)
- {
- _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;
- _container = container;
- InforNew = new ObservableCollection<InformationNew>();
- HouseCommand = new DelegateCommand(UploadHouse);
- OutWorkCommand = new DelegateCommand(UploadOutWork);
- OrderCommand = new DelegateCommand(OrderEnter);
- Products = _container.Resolve<MulProductModel>();
- if (Products == null)
- {
- Products = new MulProductModel();
- }
- //Customer = _container.Resolve<CustomerInfor>();
- //if (Customer == null)
- //{
- // Customer = new CustomerInfor();
- //}
- 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;
- if (sp != "")
- {
- TestRes(sp, result, opname);
- WriteCSV_Test(opname, sp, result);
- client.Send("TeR:检测结果上传成功");
- WriteLog("检测1#检测结果上传成功");
- }
- else
- {
- 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;
- }
- }
- var list = repository.GetFirstDefault<Quality>(c => c.QuPCode == Order);//查一个值
- 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 = DateTime.Today,
- QuPCode = Order,
- ProTName = GVariable.ProductTypeName,
- 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;
- if (sp != "")
- {
- TestRes(sp, result, opname);
- WriteCSV_Test(opname, sp, result);
- client.Send("TeR:检测结果上传成功");
- WriteLog("检测2#检测结果上传成功");
- }
- else
- {
- 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;
- }
- }
- var list = repository.GetFirstDefault<Quality>(c => c.QuPCode == Order);//查一个值
- 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 = DateTime.Today,
- QuPCode = Order,
- ProTName = GVariable.ProductTypeName,
- 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;
- if (sp != "")
- {
- TestRes(sp, result, opname);
- WriteCSV_Test(opname, sp, result);
- client.Send("TeR:检测结果上传成功");
- WriteLog("检测3#检测结果上传成功");
- }
- else
- {
- 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;
- }
- }
- var list = repository.GetFirstDefault<Quality>(c => c.QuPCode == Order);//查一个值
- 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 = DateTime.Today,
- QuPCode = Order,
- ProTName = GVariable.ProductTypeName,
- 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;
- if (sp != "")
- {
- TestRes(sp, result, opname);
- WriteCSV_Test(opname, sp, result);
- client.Send("TeR:检测结果上传成功");
- WriteLog("检测4#检测结果上传成功");
- }
- else
- {
- 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;
- }
- }
- var list = repository.GetFirstDefault<Quality>(c => c.QuPCode == Order);//查一个值
- 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 = DateTime.Today,
- QuPCode = Order,
- ProTName = GVariable.ProductTypeName,
- 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 cl = mes.Split(":")[2];
- string wu = ResWord(mes.Split(":")[3]);
- 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 = "维修",
- WorkDev = "1号维修机"
- };
- 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,
- WorkDev = productNew.WorkDev
- };
- InforNew.Add(productNew);
- _repository.Add(product);
- }));
- WriteCSV_Repair(Operator19, cl, 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);
- _logger.Error("FIX1:" + ex);
- }
- }
- }
- 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 cl = mes.Split(":")[2];
- string wu = ResWord(mes.Split(":")[3]);
- 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 = "维修",
- WorkDev = "2号维修机"
- };
- 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,
- WorkDev = productNew.WorkDev,
- };
- InforNew.Add(productNew);
- _repository.Add(product);
- }));
- WriteCSV_Repair(Operator20, cl, 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);
- _logger.Error("FIX2:" + ex);
- }
- }
- }
- 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 cl = mes.Split(":")[2];
- string wu = ResWord(mes.Split(":")[3]);
- 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 = "维修",
- WorkDev = "3号维修机"
- };
- 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,
- WorkDev = productNew.WorkDev,
- };
- InforNew.Add(productNew);
- _repository.Add(product);
- }));
- WriteCSV_Repair(Operator21, cl, 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);
- _logger.Error("FIX3:" + ex);
- }
- }
- }
- #endregion
- OperatorName(operName);
- }
- catch (Exception ex)
- {
- WriteLog($"TCPReceived:{ex.Message}", LogType.Error);
- _logger.Error("TCPReceived:" + ex);
- }
- return EasyTask.CompletedTask;
- };
- #endregion
- var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == DateTime.Today);
- if (allnumbers == null)
- {
- var al = new AllNumber()
- {
- Id = Guid.NewGuid(),
- DateA = DateTime.Today,
- PlanA = 0,
- RealityA = 0,
- OkA = 0,
- NgA = 0,
- ErrA = 0
- };
- ra = 0;
- _repository.Add(al);
- }
- 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, 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,
- WorkDev = "检测机台"
- };
- 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,
- WorkDev = productNew.WorkDev,
- };
- 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);
- _logger.Error("TEST1:" + ex);
- }
- }
- 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);
- _logger.Error("TEST2:" + ex);
- }
- }
- }
- //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);
- _logger.Error("TEST3:" + ex);
- }
- }
- }
- 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);
- _logger.Error("TEST4:" + ex);
- }
- }
- }
- }
- }
- #endregion
- //public string ShowClient()
- //{
- // //Customer.CustomerName.Add("AAAAA");
- // //Customer.CustomerName.Add("BBBBB");
- // //Customer.CustomerName.Add("CCCCC");
- // //Customer.WriteConfig();
- // Customer.ReadConfig();
- // ClientNames = Customer.CustomerName;
- // return SelectedClientName;
- //}
- private async void _timer_Elapsed1()
- {
- while (true)
- {
- try
- {
- if (Connected)
- {
- if (tcpNet.ReadInt(1500) == 1)
- {
- tcpNet.WriteInt(1500, 0);
- }
- }
- //Customer.ReadConfig();
- //ClientNames = Customer.CustomerName;
- }
- catch (Exception ex)
- {
- WriteLog("Timer:" + ex.Message, LogType.Error);
- _logger.Error("Timer:" + ex);
- }
- await Task.Delay(1000);
- }
- }
- public void ProcessFinish(object sender, StateEventArgs e)
- {
- try
- {
- var list = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);//查一个值
- Thread.Sleep(500);
- if (list != null)
- {
- list.RealityS++;
- _repository.Update(list);
- }
- int realityA = tcpNet.ReadInt(1028);
- var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == DateTime.Today);
- Thread.Sleep(500);
- if (allnumbers != null)
- {
- allnumbers.RealityA = realityA;
- _repository.Update(allnumbers);
- }
- ra++;
- _logger.Information("当天实际产量:" + ra.ToString());
- Quest(Order);
- var d1 = tcpNet.ReadInt(1090);
- var d2 = tcpNet.ReadInt(1091);
- var d3 = tcpNet.ReadInt(1092);
- soleNum = d1.ToString() + d2.ToString() + d3.ToString();
- tcpNet.Write("1026.4", false);
- }
- catch (Exception ex)
- {
- WriteLog("ProcessFinish:" + ex.Message, LogType.Error);
- _logger.Error("ProcessFinish:" + ex);
- }
- }
- string plannum; double plan;
- List<string> fbarcode = new List<string>();
- private void OrderEnter()
- {
- try
- {
- Order = Order.ToUpper();
- 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("切换订单成功");
- 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);
- //Task.Factory.StartNew(PrintCode, TaskCreationOptions.LongRunning);//打印产品码
- var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == DateTime.Today);
- if (allnumbers != null)
- {
- allnumbers.PlanA = allnumbers.PlanA + plan;
- _repository.Update(allnumbers);
- }
- }
- }
- else
- {
- WriteLog("订单错误", LogType.Error);
- }
- }
- catch (Exception ex)
- {
- WriteLog("OrderEnter1:" + ex.Message, LogType.Error);
- _logger.Error("OrderEnter1:" + ex);
- }
- }
- catch (Exception ex)
- {
- WriteLog("OrderEnter2:" + ex.Message, LogType.Error);
- _logger.Error("OrderEnter2:" + ex);
- }
- }
- private void PrintCode()
- {
- try
- {
- //打印产品码
- fbarcode.Clear();
- var customRepo = new CustomRepository();
- 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);
- string id = string.Empty;
- foreach (var item in tcpService.SocketClients.GetClients())
- {
- if (item.IP == "192.168.10.15")//15
- {
- id = item.Id;
- Thread.Sleep(500);
- tcpService.Send(id, "print:" + fbarcode[i] + ":");
- }
- }
- }
- WriteLog("产品码传输完毕");
- }
- }
- catch (Exception ex)
- {
- WriteLog("PrintCode:" + ex.Message, LogType.Error);
- _logger.Error("PrintCode:" + ex);
- }
- }
- 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("线边仓数据上传成功");
- }
- }
- 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;
- }
- }
- }
- catch (Exception ex)
- {
- WriteLog("SendPro:" + ex.Message, LogType.Error);
- _logger.Error("SendPro:" + ex);
- }
- }
- 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 = "",
- WorkDev = "1号机台"
- };
- 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,
- WorkDev = productNew.WorkDev
- };
- WriteCSV_Pro(Operator1, "1号机台", 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);
- }
- tcpNet.Write("1025.0", false);
- }));
- }
- 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 = "",
- WorkDev = "2号机台"
- };
- 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,
- WorkDev = productNew.WorkDev
- };
- WriteCSV_Pro(Operator2, "2号机台", 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);
- }
- tcpNet.Write("1025.1", false);
- }));
- }
- 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 = "",
- WorkDev = "3号机台"
- };
- 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,
- WorkDev = productNew.WorkDev,
- };
- WriteCSV_Pro(Operator3, "3号机台", 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);
- }
- tcpNet.Write("1025.2", false);
- }));
- }
- 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 = "",
- WorkDev = "4号机台"
- };
- 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,
- WorkDev = productNew.WorkDev
- };
- WriteCSV_Pro(Operator4, "4号机台", 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);
- }
- tcpNet.Write("1025.3", false);
- }));
- }
- 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 = "",
- WorkDev = "5号机台"
- };
- 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,
- WorkDev = productNew.WorkDev
- };
- WriteCSV_Pro(Operator5, "5号机台", 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);
- }
- tcpNet.Write("1025.4", false);
- }));
- }
- 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 = "",
- WorkDev = "6号机台"
- };
- 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,
- WorkDev = productNew.WorkDev
- };
- WriteCSV_Pro(Operator6, "6号机台", 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);
- }
- tcpNet.Write("1025.5", false);
- }));
- }
- 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 = "",
- WorkDev = "7号机台"
- };
- 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,
- WorkDev = productNew.WorkDev
- };
- WriteCSV_Pro(Operator7, "7号机台", 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);
- }
- tcpNet.Write("1025.8", false);
- }));
- }
- 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 = "",
- WorkDev = "8号机台"
- };
- 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,
- WorkDev = productNew.WorkDev
- };
- WriteCSV_Pro(Operator8, "8号机台", 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);
- }
- tcpNet.Write("1025.9", false);
- }));
- }
- 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 = "",
- WorkDev = "9号机台"
- };
- 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,
- WorkDev = productNew.WorkDev
- };
- WriteCSV_Pro(Operator9, "9号机台", 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);
- }
- tcpNet.Write("1025.10", false);
- }));
- }
- 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 = "",
- WorkDev = "10号机台"
- };
- 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,
- WorkDev = productNew.WorkDev
- };
- WriteCSV_Pro(Operator10, "10号机台", 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);
- }
- tcpNet.Write("1025.11", false);
- }));
- }
- 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 = "",
- WorkDev = "11号机台"
- };
- 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,
- WorkDev = productNew.WorkDev,
- };
- WriteCSV_Pro(Operator11, "11号机台", 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);
- }
- tcpNet.Write("1025.14", false);
- }));
- }
- 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 = "",
- WorkDev = "12号机台"
- };
- 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,
- WorkDev = productNew.WorkDev,
- };
- WriteCSV_Pro(Operator12, "12号机台", 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);
- }
- tcpNet.Write("1025.15", false);
- }));
- }
- 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 = "",
- WorkDev = "13号机台"
- };
- 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,
- WorkDev = productNew.WorkDev
- };
- WriteCSV_Pro(Operator13, "13号机台", 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);
- }
- tcpNet.Write("1026.0", false);
- }));
- }
- 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 = "",
- WorkDev = "14号机台"
- };
- 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,
- WorkDev = productNew.WorkDev
- };
- WriteCSV_Pro(Operator14, "14号机台", 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);
- }
- tcpNet.Write("1026.1", false);
- }
- catch (Exception ex)
- {
- WriteLog("RecordOneMessage14:" + ex.Message, LogType.Error);
- _logger.Error("RecordOneMessage14:" + ex);
- }
- }));
- }
- #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);
- _logger.Error("Timer_Elapsed:" + ex);
- }
- 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 ex)
- {
- _logger.Error("Timer_Elapsed2.1:" + ex);
- }
- }
- 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);
- _logger.Error("Timer_Elapsed2:" + ex);
- }
- finally
- {
- Thread.Sleep(1000);
- }
- }
- }
- private void Timer_Elapsed3()
- {
- while (true)
- {
- if (!Connected)
- {
- continue;
- }
- try
- {
- //切换产品
- int type = tcpNet.ReadInt(1000);
- Products.LoadParame();
- var currentProduct = Products.ProductCollection.FirstOrDefault(p => p.NameNumber == type);
- if (currentProduct != null)
- {
- GVariable.ProductTypeName = currentProduct.Name;
- }
- if (a != type && type != -1)
- {
- Change();
- }
- if (type != -1)
- {
- a = type;
- }
- }
- catch (ObjectDisposedException ex)
- {
- WriteLog("Timer_Elapsed3:" + ex.Message, LogType.Error);
- _logger.Error("Timer_Elapsed3:" + ex);
- }
- 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);
- Products.LoadParame();
- var currentProduct = Products.ProductCollection.FirstOrDefault(p => p.NameNumber == type);
- if (currentProduct != null)
- {
- proName = currentProduct.Name;
- GVariable.ProductTypeName = proName;
- }
- //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 devNum, 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();
- s22 = idPeople;
- s23 = devNum;
- s24 = proType;
- s25 = order;
- s26 = Wu;
- //=========================
- s1 = path;
- s2 = DateTime.Now.ToString("yyyyMMdd"); //表格命名以天记录
- s3 = s11 + "," + s12 + "," + s13 + "," + s14 + "," + s15 + "," + s16;
- s4 = s21 + "," + s22 + "," + s23 + "," + s24 + "," + s25 + "," + s26;
- //
- DataHelp.Save(s1, s2, s3, s4);
- }
- //绑定信息
- public void WriteCSV_Bind(string proCode, string proType, string order)
- {
- 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 = "产品码";
- s13 = "产品类型";
- s14 = "订单编号";
- //
- s21 = DateTime.Now.ToString();
- s22 = proCode;
- s23 = proType;
- s24 = order;
- //=========================
- s1 = path;
- s2 = DateTime.Now.ToString("yyyyMMdd"); //表格命名以天记录
- s3 = s11 + "," + s12 + "," + s13 + "," + s14;
- s4 = s21 + "," + s22 + "," + s23 + "," + s24;
- //
- 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();
- s22 = idPeople;
- s23 = proCode;
- s24 = res;
- //=========================
- s1 = path;
- s2 = DateTime.Now.ToString("yyyyMMdd"); //表格命名以天记录
- s3 = s11 + "," + s12 + "," + s13 + "," + s14;
- s4 = s21 + "," + s22 + "," + s23 + "," + s24;
- //
- DataHelp.Save(s1, s2, s3, s4);
- }
- //维修信息
- public void WriteCSV_Repair(string idPeople, string client, string proCode, string wu)
- {
- 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 = "维修人员ID";
- s13 = "客户";
- s14 = "产品码";
- s15 = "维修物料";
- //
- s21 = DateTime.Now.ToString();
- s22 = idPeople;
- s23 = client;
- s24 = proCode;
- s25 = wu;
- //=========================
- s1 = path;
- s2 = DateTime.Now.ToString("yyyyMMdd"); //表格命名以天记录
- s3 = s11 + "," + s12 + "," + s13 + "," + s14 + "," + s15;
- s4 = s21 + "," + s22 + "," + s23 + "," + s24 + "," + s25;
- //
- 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
- }
- }
|