12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077 |
- 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;
- 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);
- 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);
- 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);
- 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);
- 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];
- 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 = ResWord(mes.Split(":")[2]),
- 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);
- }));
- client.Send("Rep:维修信息上传成功");
- WriteLog("维修1#维修信息上传成功");
- try
- {
- DateTime dt = DateTime.Today;
- var list = _repository.GetFirstDefault<ProStatus>(c => c.DateS == dt);//查一个值
- if (list != null)
- {
- list.ErrS++;
- _repository.Update(list);
- }
- var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == dt);
- 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];
- 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 = ResWord(mes.Split(":")[2]),
- 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);
- }));
- client.Send("Rep:维修信息上传成功");
- WriteLog("维修2#维修信息上传成功");
- try
- {
- DateTime dt = DateTime.Today;
- var list = _repository.GetFirstDefault<ProStatus>(c => c.DateS == dt);//查一个值
- if (list != null)
- {
- list.ErrS++;
- _repository.Update(list);
- }
- var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == dt);
- 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];
- 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 = ResWord(mes.Split(":")[2]),
- 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);
- }));
- client.Send("Rep:维修信息上传成功");
- WriteLog("维修3#维修信息上传成功");
- try
- {
- DateTime dt = DateTime.Today;
- var list = _repository.GetFirstDefault<ProStatus>(c => c.DateS == dt);//查一个值
- if (list != null)
- {
- list.ErrS++;
- _repository.Update(list);
- }
- var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == dt);
- 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]);
- }
- }
- }
- #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
- {
- DateTime dt = DateTime.Today;
- var list = _repository.GetFirstDefault<ProStatus>(c => c.DateS == dt && c.OrdNoS == Order);//查一个值
- if (list != null)
- {
- list.OkS++;
- _repository.Update(list);
- }
- var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == dt);
- if (allnumbers != null)
- {
- allnumbers.OkA++;
- _repository.Update(allnumbers);
- }
- }
- catch (Exception ex)
- {
- WriteLog("TEST1:" + ex.Message, LogType.Error);
- }
- }
- else
- {
- try
- {
- DateTime dt = DateTime.Today;
- var list = _repository.GetFirstDefault<ProStatus>(c => c.DateS == dt && c.OrdNoS == Order);//查一个值
- if (list != null)
- {
- list.NgS++;
- _repository.Update(list);
- }
- var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == dt);
- 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
- {
- DateTime dt = DateTime.Today;
- var list = _repository.GetFirstDefault<ProStatus>(c => c.DateS == dt && c.OrdNoS == Order);//查一个值
- if (list != null)
- {
- list.OkS++;
- list.NgS--;
- _repository.Update(list);
- }
- var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == dt);
- 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
- {
- DateTime dt = DateTime.Today;
- var list = _repository.GetFirstDefault<ProStatus>(c => c.DateS == dt && c.OrdNoS == Order);//查一个值
- if (list != null)
- {
- list.NgS++;
- list.OkS--;
- _repository.Update(list);
- }
- var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == dt);
- 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);
- }
- //if (!mybool)
- //{
- // mybool = true;
- // inovanceTcp.WriteDate("D1500", 0);
- // //_logger.Information("{@Message}", "Timer:D1500_0");//后台log,会添加到数据中,不会显示到界面上
- //}
- //else
- //{
- // mybool = false;
- // inovanceTcp.WriteDate("D1500", 1);
- // //_logger.Information("{@Message}", "Timer:D1500_1");
- //}
- }
- }
- catch (Exception ex)
- {
- WriteLog("Timer:" + ex.Message, LogType.Error);
- }
- //await Task.Delay(1000);
- }
- }
- public void ProcessFinish(object sender, StateEventArgs e)
- {
- try
- {
- DateTime dt = DateTime.Today;
- var list = _repository.GetFirstDefault<ProStatus>(c => c.DateS == dt);//查一个值
- if (list != null)
- {
- list.RealityS++;
- _repository.Update(list);
- }
- var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == dt);
- 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
- {
- //if (string.IsNullOrWhiteSpace(SelectedOrderName))
- //{
- //}
- //else
- //{
- fbarcode.Clear();
- Quest(Order);
- WriteLog("切换订单成功");
- 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));
- }
- 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.14", "print:" + fbarcode[i]);
- }
- }
- }
- catch (Exception ex)
- {
- WriteLog("OrderEnter1:" + ex.Message, LogType.Error);
- }
- var outp = new ProStatus()
- {
- Id = Guid.NewGuid(),
- DateS = DateTime.Today,
- OrdNoS = Order,
- PlanS = plan,
- RealityS = 0,
- OkS = 0,
- NgS = 0,
- ErrS = 0
- };
- _repository.Add(outp);
- try
- {
- DateTime dt = DateTime.Today;
- var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == dt);
- 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);
- }
- //}
- }
- 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
- };
- 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
- };
- _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
- };
- _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
- };
- _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
- };
- _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
- };
- _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
- };
- _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
- };
- _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
- };
- _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
- };
- _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
- };
- _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
- };
- _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
- };
- _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
- };
- _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 生成二维码
- 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
- }
- }
|