MainPageViewModel.cs 132 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087
  1. using HslCommunication.Core.IMessage;
  2. using LogForceTestApp.Modules.MainModule.Models;
  3. using LogoForceTestApp.Modules.MainModule.Enums;
  4. using LogoForceTestApp.Modules.MainModule.Models;
  5. using LogoForceTestApp.Modules.MainModule.Services;
  6. using LogoForceTestApp.Services;
  7. using LogoForceTestApp.Services.Interfaces;
  8. using Newtonsoft.Json;
  9. using Newtonsoft.Json.Linq;
  10. using OxyPlot;
  11. using OxyPlot.Axes;
  12. using OxyPlot.Series;
  13. using Prism.Commands;
  14. using Prism.Events;
  15. using Prism.Mvvm;
  16. using Prism.Regions;
  17. using Prism.Services.Dialogs;
  18. using PropertyChanged;
  19. using Repository;
  20. using Repository.Entiies;
  21. using Serilog;
  22. using SkiaSharp.QrCode; //生成二维码
  23. using SkiaSharp;
  24. using StatementMachineService.Core;
  25. using StatementMachineService.Events;
  26. using System;
  27. using System.Collections.Concurrent;
  28. using System.Collections.Generic;
  29. using System.Diagnostics;
  30. using System.IO;
  31. using System.Net.Http;
  32. using System.Runtime.Serialization;
  33. using System.Security.Cryptography;
  34. using System.Text;
  35. using System.Threading;
  36. using System.Threading.Tasks;
  37. using System.Timers;
  38. using System.Windows;
  39. using Team.Utility;
  40. using static AutoMapper.Internal.ExpressionFactory;
  41. using System.Collections.ObjectModel;
  42. using TouchSocket.Core;
  43. using TouchSocket.Sockets;
  44. using Result = LogoForceTestApp.Modules.MainModule.Models.Result;
  45. using System.Windows.Media;
  46. using SkiaSharp.Views.WPF;
  47. using System.Windows.Media.Imaging;
  48. using System.Windows.Media.Media3D;
  49. using System.Drawing;
  50. using ZXing.Common;
  51. using ZXing;
  52. using HandyControl.Controls;
  53. using LogoForceTestApp.Core;
  54. using System.Windows.Documents;
  55. using System.Data.SqlTypes;
  56. using HandyControl.Data;
  57. using static SkiaSharp.HarfBuzz.SKShaper;
  58. using System.Windows.Forms;
  59. using Application = System.Windows.Application;
  60. namespace LogoForceTestApp.Modules.MainModule.ViewModels
  61. {
  62. public class MainPageViewModel : BindableBase
  63. {
  64. int _upLoadSlowTime;
  65. private bool _start;
  66. private List<DataPoint> _points = new();
  67. private readonly ConcurrentQueue<UpLoadTraceModel> _upLoadTraceModels = new();
  68. private readonly IHttpClientFactory _httpClientFactory;
  69. private readonly IScanService _scanService;
  70. private readonly IModbusTcpSlaverService _modbusTcpSlaverService;
  71. private readonly IStateService _stateService;
  72. private readonly IRepository _repository;
  73. private readonly IWritableOptions<AppSettings> _appSttings;
  74. private readonly IEventAggregator _eventAggregator;
  75. //private readonly InovanceTcp inovanceTcp;
  76. private readonly PLC tcpNet;
  77. private readonly ILogger _logger;
  78. private readonly IWarningUpdateService _warningUpdateService;
  79. private readonly IDialogService _dialogService;
  80. private readonly TcpService tcpService;
  81. private readonly Dictionary<int, string> SignalMapper;
  82. private bool _firstStart = true;
  83. private ResettableTimer _resettableTimer;
  84. public ObservableCollection<InformationNew> InforNew { get; set; }
  85. [DoNotNotify]
  86. public string CSVPath { get; set; }
  87. [DoNotNotify]
  88. public string ImagePath { get; set; }
  89. private bool _connected;
  90. public bool Connected
  91. {
  92. get
  93. {
  94. return _connected;
  95. }
  96. set { _connected = value; }
  97. }
  98. public DelegateCommand QRCommand { get; set; }
  99. public DelegateCommand HouseCommand { get; set; }
  100. public DelegateCommand OutWorkCommand { get; set; }
  101. public DelegateCommand OrderCommand { get; set; }
  102. //public string SelectedOrderName { get; set; }
  103. //public ObservableCollection<string> OrderNames { get; set; }
  104. public string Order { get; set; }
  105. public string LackHouse { get; set; }
  106. public string UsedHouse { get; set; }
  107. public string TotalHouse { get; set; }
  108. public int ActPer { get; set; }
  109. public int FallPer { get; set; }
  110. public int AbsPer { get; set; }
  111. #region Operator
  112. public string Operator1 { get; set; }
  113. public string Operator2 { get; set; }
  114. public string Operator3 { get; set; }
  115. public string Operator4 { get; set; }
  116. public string Operator5 { get; set; }
  117. public string Operator6 { get; set; }
  118. public string Operator7 { get; set; }
  119. public string Operator8 { get; set; }
  120. public string Operator9 { get; set; }
  121. public string Operator10 { get; set; }
  122. public string Operator11 { get; set; }
  123. public string Operator12 { get; set; }
  124. public string Operator13 { get; set; }
  125. public string Operator14 { get; set; }
  126. public string Operator15 { get; set; }
  127. public string Operator16 { get; set; }
  128. public string Operator17 { get; set; }
  129. public string Operator18 { get; set; }
  130. public string Operator19 { get; set; }
  131. public string Operator20 { get; set; }
  132. public string Operator21 { get; set; }
  133. #endregion
  134. #region Material
  135. public string Material1 { get; set; }
  136. public string Material2 { get; set; }
  137. public string Material3 { get; set; }
  138. public string Material4 { get; set; }
  139. public string Material5 { get; set; }
  140. public string Material6 { get; set; }
  141. public string Material7 { get; set; }
  142. public string Material8 { get; set; }
  143. public string Material9 { get; set; }
  144. public string Material10 { get; set; }
  145. public string Material11 { get; set; }
  146. public string Material12 { get; set; }
  147. public string Material13 { get; set; }
  148. public string Material14 { get; set; }
  149. public string Material15 { get; set; }
  150. public string Material16 { get; set; }
  151. public string Material17 { get; set; }
  152. public string Material18 { get; set; }
  153. public string Material19 { get; set; }
  154. public string Material20 { get; set; }
  155. public string Material21 { get; set; }
  156. #endregion
  157. #region 物料
  158. public ObservableCollection<string> listMaterial1 { get; set; }
  159. public ObservableCollection<string> listMaterial2 { get; set; }
  160. public ObservableCollection<string> listMaterial3 { get; set; }
  161. public ObservableCollection<string> listMaterial4 { get; set; }
  162. public ObservableCollection<string> listMaterial5 { get; set; }
  163. public ObservableCollection<string> listMaterial6 { get; set; }
  164. public ObservableCollection<string> listMaterial7 { get; set; }
  165. public ObservableCollection<string> listMaterial8 { get; set; }
  166. public ObservableCollection<string> listMaterial9 { get; set; }
  167. public ObservableCollection<string> listMaterial10 { get; set; }
  168. public ObservableCollection<string> listMaterial11 { get; set; }
  169. public ObservableCollection<string> listMaterial12 { get; set; }
  170. public ObservableCollection<string> listMaterial13 { get; set; }
  171. public ObservableCollection<string> listMaterial14 { get; set; }
  172. #endregion
  173. public string ProductCode { get; set; }
  174. string soleNum = null;
  175. int[] q = new int[30];
  176. string[] operName = new string[25];
  177. private System.Timers.Timer _timer;
  178. private Thread myBackUpThread;
  179. public MainPageViewModel(IHttpClientFactory httpClientFactory, IScanService scanService,
  180. IModbusTcpSlaverService modbusTcpSlaverService, IStateService stateService, IRepository repository,
  181. IWritableOptions<AppSettings> appSttings, IEventAggregator eventAggregator, PLC tcpNet,
  182. ILogger logger, IWarningUpdateService warningUpdateService, IDialogService dialogService, TcpService tcpService)
  183. {
  184. _httpClientFactory = httpClientFactory;
  185. _scanService = scanService;
  186. _modbusTcpSlaverService = modbusTcpSlaverService;
  187. _stateService = stateService;
  188. _repository = repository;
  189. _appSttings = appSttings;
  190. CSVPath = _appSttings.Value.CSVPath;
  191. ImagePath = _appSttings.Value.ImageSavePath;
  192. _eventAggregator = eventAggregator;
  193. this.tcpNet = tcpNet;
  194. _logger = logger;
  195. _warningUpdateService = warningUpdateService;
  196. _dialogService = dialogService;
  197. this.tcpService = tcpService;
  198. InforNew = new ObservableCollection<InformationNew>();
  199. HouseCommand = new DelegateCommand(UploadHouse);
  200. OutWorkCommand = new DelegateCommand(UploadOutWork);
  201. OrderCommand = new DelegateCommand(OrderEnter);
  202. Connected = tcpNet.Connect();
  203. #region tcpService
  204. tcpService.Connected = (client, e) =>
  205. {
  206. WriteLog("有客户端成功连接");
  207. return EasyTask.CompletedTask;
  208. };//有客户端成功连接
  209. tcpService.Disconnecting = (client, e) =>
  210. {
  211. return EasyTask.CompletedTask;
  212. };//有客户端正在断开连接,只有当主动断开时才有效。
  213. tcpService.Disconnected = (client, e) =>
  214. {
  215. WriteLog("有客户端断开连接");
  216. return EasyTask.CompletedTask;
  217. };//有客户端断开连接
  218. tcpService.Received = (client, e) =>
  219. {
  220. //从客户端收到信息
  221. var mes = Encoding.UTF8.GetString(e.ByteBlock.Buffer, 0, e.ByteBlock.Len);//注意:数据长度是byteBlock.Len
  222. //WriteLog($"已从{client.Id}接收到信息:{mes}");
  223. //client.Send(mes);
  224. //WriteLog("发送" + mes);
  225. try
  226. {
  227. #region 1-7
  228. if (client.IP == "192.168.10.1")//1号机
  229. {
  230. if (mes.Split(":")[0] == "WU")
  231. {
  232. Material1 = ResWord(mes.Split(":")[1]);
  233. //listMaterial1.Add(mes.Split(":")[1]);
  234. client.Send($"WU:物料上传成功");
  235. WriteLog("1#物料上传成功");
  236. }
  237. if (mes.Split(":")[0] == "Login")
  238. {
  239. string accountID = mes.Split(":")[1];
  240. Operator1 = accountID;
  241. client.Send($"LoginSuc:登录成功");
  242. WriteLog("1#登录成功");
  243. operName[0] = Operator1;
  244. }
  245. if (mes == "切换完成")
  246. {
  247. tcpNet.Write("1501.0", true);
  248. Thread.Sleep(1000);
  249. WriteLog("1#切换完成");
  250. }
  251. tcpNet.Write("1501.0", false);
  252. }
  253. if (client.IP == "192.168.10.2")//2号机
  254. {
  255. if (mes.Split(":")[0] == "WU")
  256. {
  257. Material2 = ResWord(mes.Split(":")[1]);
  258. client.Send($"WU:物料上传成功");
  259. WriteLog("2#物料上传成功");
  260. }
  261. if (mes.Split(":")[0] == "Login")
  262. {
  263. string accountID = mes.Split(":")[1];
  264. Operator2 = accountID;
  265. client.Send($"LoginSuc:登录成功");
  266. WriteLog("2#登录成功");
  267. operName[1] = Operator2;
  268. }
  269. if (mes == "切换完成")
  270. {
  271. tcpNet.Write("1501.1", true);
  272. Thread.Sleep(1000);
  273. WriteLog("2#切换完成");
  274. }
  275. tcpNet.Write("1501.1", false);
  276. }
  277. if (client.IP == "192.168.10.3")//3号机
  278. {
  279. if (mes.Split(":")[0] == "WU")
  280. {
  281. Material3 = ResWord(mes.Split(":")[1]);
  282. client.Send($"WU:物料上传成功");
  283. WriteLog("3#物料上传成功");
  284. }
  285. if (mes.Split(":")[0] == "Login")
  286. {
  287. string accountID = mes.Split(":")[1];
  288. Operator3 = accountID;
  289. client.Send($"LoginSuc:登录成功");
  290. WriteLog("3#登录成功");
  291. operName[2] = Operator3;
  292. }
  293. if (mes == "切换完成")
  294. {
  295. tcpNet.Write("1501.2", true);
  296. Thread.Sleep(1000);
  297. WriteLog("3#切换完成");
  298. }
  299. tcpNet.Write("1501.2", false);
  300. }
  301. if (client.IP == "192.168.10.4")//4号机
  302. {
  303. if (mes.Split(":")[0] == "WU")
  304. {
  305. Material4 = ResWord(mes.Split(":")[1]);
  306. client.Send($"WU:物料上传成功");
  307. WriteLog("4#物料上传成功");
  308. }
  309. if (mes.Split(":")[0] == "Login")
  310. {
  311. string accountID = mes.Split(":")[1];
  312. Operator4 = accountID;
  313. client.Send($"LoginSuc:登录成功");
  314. WriteLog("4#登录成功");
  315. operName[3] = Operator4;
  316. }
  317. if (mes == "切换完成")
  318. {
  319. tcpNet.Write("1501.3", true);
  320. Thread.Sleep(1000);
  321. WriteLog("4#切换完成");
  322. }
  323. tcpNet.Write("1501.3", false);
  324. }
  325. if (client.IP == "192.168.10.5")//5号机
  326. {
  327. if (mes.Split(":")[0] == "WU")
  328. {
  329. Material5 = ResWord(mes.Split(":")[1]);
  330. client.Send($"WU:物料上传成功");
  331. WriteLog("5#物料上传成功");
  332. }
  333. if (mes.Split(":")[0] == "Login")
  334. {
  335. string accountID = mes.Split(":")[1];
  336. Operator5 = accountID;
  337. client.Send($"LoginSuc:登录成功");
  338. WriteLog("5#登录成功");
  339. operName[4] = Operator5;
  340. }
  341. if (mes == "切换完成")
  342. {
  343. tcpNet.Write("1501.4", true);
  344. Thread.Sleep(1000);
  345. WriteLog("5#切换完成");
  346. }
  347. tcpNet.Write("1501.4", false);
  348. }
  349. if (client.IP == "192.168.10.6")//6号机
  350. {
  351. if (mes.Split(":")[0] == "WU")
  352. {
  353. Material6 = ResWord(mes.Split(":")[1]);
  354. client.Send($"WU:物料上传成功");
  355. WriteLog("6#物料上传成功");
  356. }
  357. if (mes.Split(":")[0] == "Login")
  358. {
  359. string accountID = mes.Split(":")[1];
  360. Operator6 = accountID;
  361. client.Send($"LoginSuc:登录成功");
  362. WriteLog("6#登录成功");
  363. operName[5] = Operator6;
  364. }
  365. if (mes == "切换完成")
  366. {
  367. tcpNet.Write("1501.5", true);
  368. Thread.Sleep(1000);
  369. WriteLog("6#切换完成");
  370. }
  371. tcpNet.Write("1501.5", false);
  372. }
  373. if (client.IP == "192.168.10.7")//7号机
  374. {
  375. if (mes.Split(":")[0] == "WU")
  376. {
  377. Material7 = ResWord(mes.Split(":")[1]);
  378. client.Send($"WU:物料上传成功");
  379. WriteLog("7#物料上传成功");
  380. }
  381. if (mes.Split(":")[0] == "Login")
  382. {
  383. string accountID = mes.Split(":")[1];
  384. Operator7 = accountID;
  385. client.Send($"LoginSuc:登录成功");
  386. WriteLog("7#登录成功");
  387. operName[6] = Operator7;
  388. }
  389. if (mes == "切换完成")
  390. {
  391. tcpNet.Write("1501.6", true);
  392. Thread.Sleep(1000);
  393. WriteLog("7#切换完成");
  394. }
  395. tcpNet.Write("1501.6", false);
  396. }
  397. #endregion
  398. #region 7-14
  399. if (client.IP == "192.168.10.8")//8号机
  400. {
  401. if (mes.Split(":")[0] == "WU")
  402. {
  403. Material8 = ResWord(mes.Split(":")[1]);
  404. client.Send($"WU:物料上传成功");
  405. WriteLog("8#物料上传成功");
  406. }
  407. if (mes.Split(":")[0] == "Login")
  408. {
  409. string accountID = mes.Split(":")[1];
  410. Operator8 = accountID;
  411. client.Send($"LoginSuc:登录成功");
  412. WriteLog("8#登录成功");
  413. operName[7] = Operator8;
  414. }
  415. if (mes == "切换完成")
  416. {
  417. tcpNet.Write("1501.7", true);
  418. Thread.Sleep(1000);
  419. WriteLog("8#切换完成");
  420. }
  421. tcpNet.Write("1501.7", false);
  422. }
  423. if (client.IP == "192.168.10.9")//9号机
  424. {
  425. if (mes.Split(":")[0] == "WU")
  426. {
  427. Material9 = ResWord(mes.Split(":")[1]);
  428. client.Send($"WU:物料上传成功");
  429. WriteLog("9#物料上传成功");
  430. }
  431. if (mes.Split(":")[0] == "Login")
  432. {
  433. string accountID = mes.Split(":")[1];
  434. Operator9 = accountID;
  435. client.Send($"LoginSuc:登录成功");
  436. WriteLog("9#登录成功");
  437. operName[8] = Operator9;
  438. }
  439. if (mes == "切换完成")
  440. {
  441. tcpNet.Write("1501.8", true);
  442. Thread.Sleep(1000);
  443. WriteLog("9#切换完成");
  444. }
  445. tcpNet.Write("1501.8", false);
  446. }
  447. if (client.IP == "192.168.10.10")//10号机
  448. {
  449. if (mes.Split(":")[0] == "WU")
  450. {
  451. Material10 = ResWord(mes.Split(":")[1]);
  452. client.Send($"WU:物料上传成功");
  453. WriteLog("10#物料上传成功");
  454. }
  455. if (mes.Split(":")[0] == "Login")
  456. {
  457. string accountID = mes.Split(":")[1];
  458. Operator10 = accountID;
  459. client.Send($"LoginSuc:登录成功");
  460. WriteLog("10#登录成功");
  461. operName[9] = Operator10;
  462. }
  463. if (mes == "切换完成")
  464. {
  465. tcpNet.Write("1501.9", true);
  466. Thread.Sleep(1000);
  467. WriteLog("10#切换完成");
  468. }
  469. tcpNet.Write("1501.9", false);
  470. }
  471. if (client.IP == "192.168.10.11")//11号机
  472. {
  473. if (mes.Split(":")[0] == "WU")
  474. {
  475. Material11 = ResWord(mes.Split(":")[1]);
  476. client.Send($"WU:物料上传成功");
  477. WriteLog("11#物料上传成功");
  478. }
  479. if (mes.Split(":")[0] == "Login")
  480. {
  481. string accountID = mes.Split(":")[1];
  482. Operator11 = accountID;
  483. client.Send($"LoginSuc:登录成功");
  484. WriteLog("11#登录成功");
  485. operName[10] = Operator11;
  486. }
  487. if (mes == "切换完成")
  488. {
  489. tcpNet.Write("1501.10", true);
  490. Thread.Sleep(1000);
  491. WriteLog("11#切换完成");
  492. }
  493. tcpNet.Write("1501.10", false);
  494. }
  495. if (client.IP == "192.168.10.12")//12号机
  496. {
  497. if (mes.Split(":")[0] == "WU")
  498. {
  499. Material12 = ResWord(mes.Split(":")[1]);
  500. client.Send($"WU:物料上传成功");
  501. WriteLog("12#物料上传成功");
  502. }
  503. if (mes.Split(":")[0] == "Login")
  504. {
  505. string accountID = mes.Split(":")[1];
  506. Operator12 = accountID;
  507. client.Send($"LoginSuc:登录成功");
  508. WriteLog("12#登录成功");
  509. operName[11] = Operator12;
  510. }
  511. if (mes == "切换完成")
  512. {
  513. tcpNet.Write("1501.11", true);
  514. Thread.Sleep(1000);
  515. WriteLog("12#切换完成");
  516. }
  517. tcpNet.Write("1501.11", false);
  518. }
  519. if (client.IP == "192.168.10.13")//13号机
  520. {
  521. if (mes.Split(":")[0] == "WU")
  522. {
  523. Material13 = ResWord(mes.Split(":")[1]);
  524. client.Send($"WU:物料上传成功");
  525. WriteLog("13#物料上传成功");
  526. }
  527. if (mes.Split(":")[0] == "Login")
  528. {
  529. string accountID = mes.Split(":")[1];
  530. Operator13 = accountID;
  531. client.Send($"LoginSuc:登录成功");
  532. WriteLog("13#登录成功");
  533. operName[12] = Operator13;
  534. }
  535. if (mes == "切换完成")
  536. {
  537. tcpNet.Write("1501.12", true);
  538. Thread.Sleep(1000);
  539. WriteLog("13#切换完成");
  540. }
  541. tcpNet.Write("1501.12", false);
  542. }
  543. if (client.IP == "192.168.10.14")//14号机
  544. {
  545. if (mes.Split(":")[0] == "WU")
  546. {
  547. Material14 = ResWord(mes.Split(":")[1]);
  548. client.Send($"WU:物料上传成功");
  549. WriteLog("14#物料上传成功");
  550. }
  551. if (mes.Split(":")[0] == "Login")
  552. {
  553. string accountID = mes.Split(":")[1];
  554. Operator14 = accountID;
  555. client.Send($"LoginSuc:登录成功");
  556. WriteLog("14#登录成功");
  557. operName[13] = Operator14;
  558. }
  559. if (mes == "切换完成")
  560. {
  561. tcpNet.Write("1501.13", true);
  562. Thread.Sleep(1000);
  563. WriteLog("14#切换完成");
  564. }
  565. tcpNet.Write("1501.13", false);
  566. }
  567. #endregion
  568. #region 检测机
  569. if (client.IP == "192.168.10.15")//检测1
  570. {
  571. if (mes.Split(":")[0] == "Bind")
  572. {
  573. Bind(mes.Split(":")[1]);
  574. client.Send("B:绑定成功");
  575. WriteLog("检测1#绑定成功");
  576. }
  577. if (mes.Split(":")[0] == "TestRes")
  578. {
  579. string sp = mes.Split(":")[1];//产品码
  580. string result = mes.Split(":")[2];
  581. string opname = Operator15;
  582. TestRes(sp, result, opname);
  583. client.Send("TeR:检测结果上传成功");
  584. WriteLog("检测1#检测结果上传成功");
  585. }
  586. if (mes.Split(":")[0] == "Test")
  587. {
  588. for (int i = 0; i < 30; i++)
  589. {
  590. if (mes.Split(":")[i + 1] == "1")
  591. {
  592. q[i] = 1;
  593. }
  594. else
  595. {
  596. q[i] = 0;
  597. }
  598. }
  599. //string str = DateTime.Now.ToString("yyyy/MM/dd");
  600. DateTime dt = DateTime.Today;
  601. var list = repository.GetFirstDefault<Quality>(c => c.DateQuality == dt);//查一个值
  602. if (list != null)
  603. {
  604. list.Q1 = list.Q1 + q[0];
  605. list.Q2 = list.Q2 + q[1];
  606. list.Q3 = list.Q3 + q[2];
  607. list.Q4 = list.Q4 + q[3];
  608. list.Q5 = list.Q5 + q[4];
  609. list.Q6 = list.Q6 + q[5];
  610. list.Q7 = list.Q7 + q[6];
  611. list.Q8 = list.Q8 + q[7];
  612. list.Q9 = list.Q9 + q[8];
  613. list.Q10 = list.Q10 + q[9];
  614. list.Q11 = list.Q11 + q[10];
  615. list.Q12 = list.Q12 + q[11];
  616. list.Q13 = list.Q13 + q[12];
  617. list.Q14 = list.Q14 + q[13];
  618. list.Q15 = list.Q15 + q[14];
  619. list.Q16 = list.Q16 + q[15];
  620. list.Q17 = list.Q17 + q[16];
  621. list.Q18 = list.Q18 + q[17];
  622. list.Q19 = list.Q19 + q[18];
  623. list.Q20 = list.Q20 + q[19];
  624. list.Q21 = list.Q21 + q[20];
  625. list.Q22 = list.Q22 + q[21];
  626. list.Q23 = list.Q23 + q[22];
  627. list.Q24 = list.Q24 + q[23];
  628. list.Q25 = list.Q25 + q[24];
  629. list.Q26 = list.Q26 + q[25];
  630. list.Q27 = list.Q27 + q[26];
  631. list.Q28 = list.Q28 + q[27];
  632. list.Q29 = list.Q29 + q[28];
  633. list.Q30 = list.Q30 + q[29];
  634. _repository.Update(list);
  635. client.Send("Te:上传成功");
  636. WriteLog("检测1#上传成功");
  637. }
  638. else
  639. {
  640. var item = new Quality()
  641. {
  642. Id = Guid.NewGuid(),
  643. DateQuality = dt,
  644. Q1 = q[0],
  645. Q2 = q[1],
  646. Q3 = q[2],
  647. Q4 = q[3],
  648. Q5 = q[4],
  649. Q6 = q[5],
  650. Q7 = q[6],
  651. Q8 = q[7],
  652. Q9 = q[8],
  653. Q10 = q[9],
  654. Q11 = q[10],
  655. Q12 = q[11],
  656. Q13 = q[12],
  657. Q14 = q[13],
  658. Q15 = q[14],
  659. Q16 = q[15],
  660. Q17 = q[16],
  661. Q18 = q[17],
  662. Q19 = q[18],
  663. Q20 = q[19],
  664. Q21 = q[20],
  665. Q22 = q[21],
  666. Q23 = q[22],
  667. Q24 = q[23],
  668. Q25 = q[24],
  669. Q26 = q[25],
  670. Q27 = q[26],
  671. Q28 = q[27],
  672. Q29 = q[28],
  673. Q30 = q[29],
  674. };
  675. _repository.Add(item);
  676. client.Send("Te:上传成功");
  677. WriteLog("检测1#上传成功");
  678. }
  679. }
  680. if (mes == "切换完成")
  681. {
  682. tcpNet.Write("1501.14", true);
  683. Thread.Sleep(1000);
  684. WriteLog("检测1#切换完成");
  685. }
  686. tcpNet.Write("1501.14", false);
  687. if (mes.Split(":")[0] == "Login")
  688. {
  689. string accountID = mes.Split(":")[1];
  690. Operator15 = accountID;
  691. client.Send($"LoginSuc:登录成功");
  692. WriteLog("15#登录成功");
  693. operName[14] = Operator15;
  694. }
  695. }
  696. if (client.IP == "192.168.10.16")//检测2
  697. {
  698. if (mes.Split(":")[0] == "TestRes")
  699. {
  700. string sp = mes.Split(":")[1];
  701. string result = mes.Split(":")[2];
  702. string opname = Operator16;
  703. TestRes(sp, result, opname);
  704. client.Send("TeR:检测结果上传成功");
  705. WriteLog("检测2#检测结果上传成功");
  706. }
  707. if (mes.Split(":")[0] == "Test")
  708. {
  709. for (int i = 0; i < 30; i++)
  710. {
  711. if (mes.Split(":")[i + 1] == "1")
  712. {
  713. q[i] = 1;
  714. }
  715. else
  716. {
  717. q[i] = 0;
  718. }
  719. }
  720. DateTime dt = DateTime.Today;
  721. var list = repository.GetFirstDefault<Quality>(c => c.DateQuality == dt);//查一个值
  722. if (list != null)
  723. {
  724. list.Q1 = list.Q1 + q[0];
  725. list.Q2 = list.Q2 + q[1];
  726. list.Q3 = list.Q3 + q[2];
  727. list.Q4 = list.Q4 + q[3];
  728. list.Q5 = list.Q5 + q[4];
  729. list.Q6 = list.Q6 + q[5];
  730. list.Q7 = list.Q7 + q[6];
  731. list.Q8 = list.Q8 + q[7];
  732. list.Q9 = list.Q9 + q[8];
  733. list.Q10 = list.Q10 + q[9];
  734. list.Q11 = list.Q11 + q[10];
  735. list.Q12 = list.Q12 + q[11];
  736. list.Q13 = list.Q13 + q[12];
  737. list.Q14 = list.Q14 + q[13];
  738. list.Q15 = list.Q15 + q[14];
  739. list.Q16 = list.Q16 + q[15];
  740. list.Q17 = list.Q17 + q[16];
  741. list.Q18 = list.Q18 + q[17];
  742. list.Q19 = list.Q19 + q[18];
  743. list.Q20 = list.Q20 + q[19];
  744. list.Q21 = list.Q21 + q[20];
  745. list.Q22 = list.Q22 + q[21];
  746. list.Q23 = list.Q23 + q[22];
  747. list.Q24 = list.Q24 + q[23];
  748. list.Q25 = list.Q25 + q[24];
  749. list.Q26 = list.Q26 + q[25];
  750. list.Q27 = list.Q27 + q[26];
  751. list.Q28 = list.Q28 + q[27];
  752. list.Q29 = list.Q29 + q[28];
  753. list.Q30 = list.Q30 + q[29];
  754. _repository.Update(list);
  755. client.Send("Te:上传成功");
  756. WriteLog("检测2#上传成功");
  757. }
  758. else
  759. {
  760. var item = new Quality()
  761. {
  762. Id = Guid.NewGuid(),
  763. DateQuality = dt,
  764. Q1 = q[0],
  765. Q2 = q[1],
  766. Q3 = q[2],
  767. Q4 = q[3],
  768. Q5 = q[4],
  769. Q6 = q[5],
  770. Q7 = q[6],
  771. Q8 = q[7],
  772. Q9 = q[8],
  773. Q10 = q[9],
  774. Q11 = q[10],
  775. Q12 = q[11],
  776. Q13 = q[12],
  777. Q14 = q[13],
  778. Q15 = q[14],
  779. Q16 = q[15],
  780. Q17 = q[16],
  781. Q18 = q[17],
  782. Q19 = q[18],
  783. Q20 = q[19],
  784. Q21 = q[20],
  785. Q22 = q[21],
  786. Q23 = q[22],
  787. Q24 = q[23],
  788. Q25 = q[24],
  789. Q26 = q[25],
  790. Q27 = q[26],
  791. Q28 = q[27],
  792. Q29 = q[28],
  793. Q30 = q[29],
  794. };
  795. _repository.Add(item);
  796. client.Send("Te:上传成功");
  797. WriteLog("检测2#上传成功");
  798. }
  799. }
  800. if (mes == "切换完成")
  801. {
  802. tcpNet.Write("1501.15", true);
  803. Thread.Sleep(1000);
  804. WriteLog("检测2#切换完成");
  805. }
  806. tcpNet.Write("1501.15", false);
  807. if (mes.Split(":")[0] == "Login")
  808. {
  809. string accountID = mes.Split(":")[1];
  810. Operator16 = accountID;
  811. client.Send($"LoginSuc:登录成功");
  812. WriteLog("16#登录成功");
  813. operName[15] = Operator16;
  814. }
  815. }
  816. if (client.IP == "192.168.10.17")//检测3
  817. {
  818. if (mes.Split(":")[0] == "TestRes")
  819. {
  820. string sp = mes.Split(":")[1];
  821. string result = mes.Split(":")[2];
  822. string opname = Operator17;
  823. TestRes(sp, result, opname);
  824. client.Send("TeR:检测结果上传成功");
  825. WriteLog("检测3#检测结果上传成功");
  826. }
  827. if (mes.Split(":")[0] == "Test")
  828. {
  829. for (int i = 0; i < 30; i++)
  830. {
  831. if (mes.Split(":")[i + 1] == "1")
  832. {
  833. q[i] = 1;
  834. }
  835. else
  836. {
  837. q[i] = 0;
  838. }
  839. }
  840. DateTime dt = DateTime.Today;
  841. var list = repository.GetFirstDefault<Quality>(c => c.DateQuality == dt);//查一个值
  842. if (list != null)
  843. {
  844. list.Q1 = list.Q1 + q[0];
  845. list.Q2 = list.Q2 + q[1];
  846. list.Q3 = list.Q3 + q[2];
  847. list.Q4 = list.Q4 + q[3];
  848. list.Q5 = list.Q5 + q[4];
  849. list.Q6 = list.Q6 + q[5];
  850. list.Q7 = list.Q7 + q[6];
  851. list.Q8 = list.Q8 + q[7];
  852. list.Q9 = list.Q9 + q[8];
  853. list.Q10 = list.Q10 + q[9];
  854. list.Q11 = list.Q11 + q[10];
  855. list.Q12 = list.Q12 + q[11];
  856. list.Q13 = list.Q13 + q[12];
  857. list.Q14 = list.Q14 + q[13];
  858. list.Q15 = list.Q15 + q[14];
  859. list.Q16 = list.Q16 + q[15];
  860. list.Q17 = list.Q17 + q[16];
  861. list.Q18 = list.Q18 + q[17];
  862. list.Q19 = list.Q19 + q[18];
  863. list.Q20 = list.Q20 + q[19];
  864. list.Q21 = list.Q21 + q[20];
  865. list.Q22 = list.Q22 + q[21];
  866. list.Q23 = list.Q23 + q[22];
  867. list.Q24 = list.Q24 + q[23];
  868. list.Q25 = list.Q25 + q[24];
  869. list.Q26 = list.Q26 + q[25];
  870. list.Q27 = list.Q27 + q[26];
  871. list.Q28 = list.Q28 + q[27];
  872. list.Q29 = list.Q29 + q[28];
  873. list.Q30 = list.Q30 + q[29];
  874. _repository.Update(list);
  875. client.Send("Te:上传成功");
  876. WriteLog("检测3#上传成功");
  877. }
  878. else
  879. {
  880. var item = new Quality()
  881. {
  882. Id = Guid.NewGuid(),
  883. DateQuality = dt,
  884. Q1 = q[0],
  885. Q2 = q[1],
  886. Q3 = q[2],
  887. Q4 = q[3],
  888. Q5 = q[4],
  889. Q6 = q[5],
  890. Q7 = q[6],
  891. Q8 = q[7],
  892. Q9 = q[8],
  893. Q10 = q[9],
  894. Q11 = q[10],
  895. Q12 = q[11],
  896. Q13 = q[12],
  897. Q14 = q[13],
  898. Q15 = q[14],
  899. Q16 = q[15],
  900. Q17 = q[16],
  901. Q18 = q[17],
  902. Q19 = q[18],
  903. Q20 = q[19],
  904. Q21 = q[20],
  905. Q22 = q[21],
  906. Q23 = q[22],
  907. Q24 = q[23],
  908. Q25 = q[24],
  909. Q26 = q[25],
  910. Q27 = q[26],
  911. Q28 = q[27],
  912. Q29 = q[28],
  913. Q30 = q[29],
  914. };
  915. _repository.Add(item);
  916. client.Send("Te:上传成功");
  917. WriteLog("检测3#上传成功");
  918. }
  919. }
  920. if (mes == "切换完成")
  921. {
  922. tcpNet.Write("1502.0", true);
  923. Thread.Sleep(1000);
  924. WriteLog("检测3#切换完成");
  925. }
  926. tcpNet.Write("1502.0", false);
  927. if (mes.Split(":")[0] == "Login")
  928. {
  929. string accountID = mes.Split(":")[1];
  930. Operator17 = accountID;
  931. client.Send($"LoginSuc:登录成功");
  932. WriteLog("17#登录成功");
  933. operName[16] = Operator17;
  934. }
  935. }
  936. if (client.IP == "192.168.10.18")//检测4
  937. {
  938. if (mes.Split(":")[0] == "TestRes")
  939. {
  940. string sp = mes.Split(":")[1];
  941. string result = mes.Split(":")[2];
  942. string opname = Operator18;
  943. TestRes(sp, result, opname);
  944. client.Send("TeR:检测结果上传成功");
  945. WriteLog("检测4#检测结果上传成功");
  946. }
  947. if (mes.Split(":")[0] == "Test")
  948. {
  949. for (int i = 0; i < 30; i++)
  950. {
  951. if (mes.Split(":")[i + 1] == "1")
  952. {
  953. q[i] = 1;
  954. }
  955. else
  956. {
  957. q[i] = 0;
  958. }
  959. }
  960. DateTime dt = DateTime.Today;
  961. var list = repository.GetFirstDefault<Quality>(c => c.DateQuality == dt);//查一个值
  962. if (list != null)
  963. {
  964. list.Q1 = list.Q1 + q[0];
  965. list.Q2 = list.Q2 + q[1];
  966. list.Q3 = list.Q3 + q[2];
  967. list.Q4 = list.Q4 + q[3];
  968. list.Q5 = list.Q5 + q[4];
  969. list.Q6 = list.Q6 + q[5];
  970. list.Q7 = list.Q7 + q[6];
  971. list.Q8 = list.Q8 + q[7];
  972. list.Q9 = list.Q9 + q[8];
  973. list.Q10 = list.Q10 + q[9];
  974. list.Q11 = list.Q11 + q[10];
  975. list.Q12 = list.Q12 + q[11];
  976. list.Q13 = list.Q13 + q[12];
  977. list.Q14 = list.Q14 + q[13];
  978. list.Q15 = list.Q15 + q[14];
  979. list.Q16 = list.Q16 + q[15];
  980. list.Q17 = list.Q17 + q[16];
  981. list.Q18 = list.Q18 + q[17];
  982. list.Q19 = list.Q19 + q[18];
  983. list.Q20 = list.Q20 + q[19];
  984. list.Q21 = list.Q21 + q[20];
  985. list.Q22 = list.Q22 + q[21];
  986. list.Q23 = list.Q23 + q[22];
  987. list.Q24 = list.Q24 + q[23];
  988. list.Q25 = list.Q25 + q[24];
  989. list.Q26 = list.Q26 + q[25];
  990. list.Q27 = list.Q27 + q[26];
  991. list.Q28 = list.Q28 + q[27];
  992. list.Q29 = list.Q29 + q[28];
  993. list.Q30 = list.Q30 + q[29];
  994. _repository.Update(list);
  995. client.Send("Te:上传成功");
  996. WriteLog("检测4#上传成功");
  997. }
  998. else
  999. {
  1000. var item = new Quality()
  1001. {
  1002. Id = Guid.NewGuid(),
  1003. DateQuality = dt,
  1004. Q1 = q[0],
  1005. Q2 = q[1],
  1006. Q3 = q[2],
  1007. Q4 = q[3],
  1008. Q5 = q[4],
  1009. Q6 = q[5],
  1010. Q7 = q[6],
  1011. Q8 = q[7],
  1012. Q9 = q[8],
  1013. Q10 = q[9],
  1014. Q11 = q[10],
  1015. Q12 = q[11],
  1016. Q13 = q[12],
  1017. Q14 = q[13],
  1018. Q15 = q[14],
  1019. Q16 = q[15],
  1020. Q17 = q[16],
  1021. Q18 = q[17],
  1022. Q19 = q[18],
  1023. Q20 = q[19],
  1024. Q21 = q[20],
  1025. Q22 = q[21],
  1026. Q23 = q[22],
  1027. Q24 = q[23],
  1028. Q25 = q[24],
  1029. Q26 = q[25],
  1030. Q27 = q[26],
  1031. Q28 = q[27],
  1032. Q29 = q[28],
  1033. Q30 = q[29],
  1034. };
  1035. _repository.Add(item);
  1036. client.Send("Te:上传成功");
  1037. WriteLog("检测4#上传成功");
  1038. }
  1039. }
  1040. if (mes == "切换完成")
  1041. {
  1042. tcpNet.Write("1502.1", true);
  1043. Thread.Sleep(1000);
  1044. WriteLog("检测4#切换完成");
  1045. }
  1046. tcpNet.Write("1502.1", false);
  1047. if (mes.Split(":")[0] == "Login")
  1048. {
  1049. string accountID = mes.Split(":")[1];
  1050. Operator18 = accountID;
  1051. client.Send($"LoginSuc:登录成功");
  1052. WriteLog("18#登录成功");
  1053. operName[17] = Operator18;
  1054. }
  1055. }
  1056. #endregion
  1057. #region 维修机
  1058. if (client.IP == "192.168.10.19")//维修1
  1059. {
  1060. if (mes.Split(":")[0] == "Login")
  1061. {
  1062. string accountID = mes.Split(":")[1];
  1063. Operator19 = accountID;
  1064. client.Send($"LoginSuc:登录成功");
  1065. WriteLog("19#登录成功");
  1066. operName[18] = Operator19;
  1067. }
  1068. if (mes.Split(":")[0] == "Fix")
  1069. {
  1070. string sp = mes.Split(":")[1];
  1071. var res = repository.GetFirstDefault<Information>(c => c.ProCode == sp);
  1072. if (res != null)
  1073. {
  1074. Application.Current.Dispatcher.Invoke(new Action(() =>
  1075. {
  1076. var productNew = new InformationNew
  1077. {
  1078. OperatorCode = Operator19,
  1079. ItemCode = ResWord(mes.Split(":")[2]),
  1080. SpendTime = 0,
  1081. CreateTime = DateTime.Today,
  1082. ProType = proName,
  1083. ProNo = "",
  1084. ProCode = sp,
  1085. OrderNo = "",
  1086. TestResult = "维修"
  1087. };
  1088. var product = new Information()
  1089. {
  1090. CreateTime = productNew.CreateTime,
  1091. Id = Guid.NewGuid(),
  1092. OperatorCode = productNew.OperatorCode,
  1093. ItemCode = productNew.ItemCode,
  1094. SpendTime = productNew.SpendTime,
  1095. ProType = productNew.ProType,
  1096. ProNo = productNew.ProNo,
  1097. ProCode = productNew.ProCode,
  1098. OrderNo = productNew.OrderNo,
  1099. TestResult = productNew.TestResult
  1100. };
  1101. InforNew.Add(productNew);
  1102. _repository.Add(product);
  1103. }));
  1104. client.Send("Rep:维修信息上传成功");
  1105. WriteLog("维修1#维修信息上传成功");
  1106. try
  1107. {
  1108. DateTime dt = DateTime.Today;
  1109. var list = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);//查一个值
  1110. if (list != null)
  1111. {
  1112. list.ErrS++;
  1113. _repository.Update(list);
  1114. }
  1115. var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == dt);
  1116. if (allnumbers != null)
  1117. {
  1118. allnumbers.ErrA++;
  1119. _repository.Update(allnumbers);
  1120. }
  1121. }
  1122. catch (Exception ex)
  1123. {
  1124. WriteLog("FIX1:" + ex.Message, LogType.Error);
  1125. }
  1126. }
  1127. }
  1128. }
  1129. if (client.IP == "192.168.10.20")//维修2
  1130. {
  1131. if (mes.Split(":")[0] == "Login")
  1132. {
  1133. string accountID = mes.Split(":")[1];
  1134. Operator20 = accountID;
  1135. client.Send($"LoginSuc:登录成功");
  1136. WriteLog("20#登录成功");
  1137. operName[19] = Operator20;
  1138. }
  1139. if (mes.Split(":")[0] == "Fix")
  1140. {
  1141. string sp = mes.Split(":")[1];
  1142. var res = repository.GetFirstDefault<Information>(c => c.ProCode == sp);
  1143. if (res != null)
  1144. {
  1145. Application.Current.Dispatcher.Invoke(new Action(() =>
  1146. {
  1147. var productNew = new InformationNew
  1148. {
  1149. OperatorCode = Operator20,
  1150. ItemCode = ResWord(mes.Split(":")[2]),
  1151. SpendTime = 0,
  1152. CreateTime = DateTime.Today,
  1153. ProType = proName,
  1154. ProNo = "",
  1155. ProCode = sp,
  1156. OrderNo = "",
  1157. TestResult = "维修"
  1158. };
  1159. var product = new Information()
  1160. {
  1161. CreateTime = productNew.CreateTime,
  1162. Id = Guid.NewGuid(),
  1163. OperatorCode = productNew.OperatorCode,
  1164. ItemCode = productNew.ItemCode,
  1165. SpendTime = productNew.SpendTime,
  1166. ProType = productNew.ProType,
  1167. ProNo = productNew.ProNo,
  1168. ProCode = productNew.ProCode,
  1169. OrderNo = productNew.OrderNo,
  1170. TestResult = productNew.TestResult
  1171. };
  1172. InforNew.Add(productNew);
  1173. _repository.Add(product);
  1174. }));
  1175. client.Send("Rep:维修信息上传成功");
  1176. WriteLog("维修2#维修信息上传成功");
  1177. try
  1178. {
  1179. DateTime dt = DateTime.Today;
  1180. var list = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);//查一个值
  1181. if (list != null)
  1182. {
  1183. list.ErrS++;
  1184. _repository.Update(list);
  1185. }
  1186. var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == dt);
  1187. if (allnumbers != null)
  1188. {
  1189. allnumbers.ErrA++;
  1190. _repository.Update(allnumbers);
  1191. }
  1192. }
  1193. catch (Exception ex)
  1194. {
  1195. WriteLog("FIX2:" + ex.Message, LogType.Error);
  1196. }
  1197. }
  1198. }
  1199. }
  1200. if (client.IP == "192.168.10.21")//维修3
  1201. {
  1202. if (mes.Split(":")[0] == "Login")
  1203. {
  1204. string accountID = mes.Split(":")[1];
  1205. Operator21 = accountID;
  1206. client.Send($"LoginSuc:登录成功");
  1207. WriteLog("21#登录成功");
  1208. operName[20] = Operator21;
  1209. }
  1210. if (mes.Split(":")[0] == "Fix")
  1211. {
  1212. string sp = mes.Split(":")[1];
  1213. var res = repository.GetFirstDefault<Information>(c => c.ProCode == sp);
  1214. if (res != null)
  1215. {
  1216. Application.Current.Dispatcher.Invoke(new Action(() =>
  1217. {
  1218. var productNew = new InformationNew
  1219. {
  1220. OperatorCode = Operator21,
  1221. ItemCode = ResWord(mes.Split(":")[2]),
  1222. SpendTime = 0,
  1223. CreateTime = DateTime.Today,
  1224. ProType = proName,
  1225. ProNo = "",
  1226. ProCode = sp,
  1227. OrderNo = "",
  1228. TestResult = "维修"
  1229. };
  1230. var product = new Information()
  1231. {
  1232. CreateTime = productNew.CreateTime,
  1233. Id = Guid.NewGuid(),
  1234. OperatorCode = productNew.OperatorCode,
  1235. ItemCode = productNew.ItemCode,
  1236. SpendTime = productNew.SpendTime,
  1237. ProType = productNew.ProType,
  1238. ProNo = productNew.ProNo,
  1239. ProCode = productNew.ProCode,
  1240. OrderNo = productNew.OrderNo,
  1241. TestResult = productNew.TestResult
  1242. };
  1243. InforNew.Add(productNew);
  1244. _repository.Add(product);
  1245. }));
  1246. client.Send("Rep:维修信息上传成功");
  1247. WriteLog("维修3#维修信息上传成功");
  1248. try
  1249. {
  1250. DateTime dt = DateTime.Today;
  1251. var list = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);//查一个值
  1252. if (list != null)
  1253. {
  1254. list.ErrS++;
  1255. _repository.Update(list);
  1256. }
  1257. var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == dt);
  1258. if (allnumbers != null)
  1259. {
  1260. allnumbers.ErrA++;
  1261. _repository.Update(allnumbers);
  1262. }
  1263. }
  1264. catch (Exception ex)
  1265. {
  1266. WriteLog("FIX3:" + ex.Message, LogType.Error);
  1267. }
  1268. }
  1269. }
  1270. }
  1271. #endregion
  1272. OperatorName(operName);
  1273. }
  1274. catch (Exception ex)
  1275. {
  1276. WriteLog($"TCPReceived:{ex.Message}");
  1277. }
  1278. return EasyTask.CompletedTask;
  1279. };
  1280. #endregion
  1281. SignalMapper = new Dictionary<int, string>
  1282. {
  1283. {1, "1025.0" },
  1284. {2, "1025.1" },
  1285. {3, "1025.2" },
  1286. {4, "1025.3" },
  1287. {5, "1025.4" },
  1288. {6, "1025.5" },
  1289. {7, "1025.8" },
  1290. {8, "1025.9" },
  1291. {9, "1025.10" },
  1292. {10, "1025.11" },
  1293. {11, "1025.14" },
  1294. {12, "1025.15" },
  1295. {13, "1026.0" },
  1296. {14, "1026.1" },
  1297. {15, "1026.4" },//完成
  1298. };
  1299. _stateService.CreateMachine(1, RecordOneMessage1, null);
  1300. _stateService.CreateMachine(2, RecordOneMessage2, null);
  1301. _stateService.CreateMachine(3, RecordOneMessage3, null);
  1302. _stateService.CreateMachine(4, RecordOneMessage4, null);
  1303. _stateService.CreateMachine(5, RecordOneMessage5, null);
  1304. _stateService.CreateMachine(6, RecordOneMessage6, null);
  1305. _stateService.CreateMachine(7, RecordOneMessage7, null);
  1306. _stateService.CreateMachine(8, RecordOneMessage8, null);
  1307. _stateService.CreateMachine(9, RecordOneMessage9, null);
  1308. _stateService.CreateMachine(10, RecordOneMessage10, null);
  1309. _stateService.CreateMachine(11, RecordOneMessage11, null);
  1310. _stateService.CreateMachine(12, RecordOneMessage12, null);
  1311. _stateService.CreateMachine(13, RecordOneMessage13, null);
  1312. _stateService.CreateMachine(14, RecordOneMessage14, null);
  1313. _stateService.CreateMachine(15, ProcessFinish, null);
  1314. Task.Factory.StartNew(Timer_Elapsed, TaskCreationOptions.LongRunning);
  1315. Task.Factory.StartNew(Timer_Elapsed2, TaskCreationOptions.LongRunning);
  1316. Task.Factory.StartNew(Timer_Elapsed3, TaskCreationOptions.LongRunning);
  1317. QRCommand = new DelegateCommand(QRcode);
  1318. //_eventAggregator.GetEvent<FileChangedEvent>().Subscribe(ReadConfig);
  1319. myBackUpThread = new Thread(_timer_Elapsed1) { IsBackground = true };
  1320. myBackUpThread.Start();
  1321. }
  1322. public void Bind(string procode)
  1323. {
  1324. var res = _repository.GetAllQuery<Information>(c => c.ProNo == soleNum);
  1325. if (res != null)
  1326. {
  1327. for (int i = 0; i < res.Count; i++)
  1328. {
  1329. res[i].ProCode = procode;
  1330. _repository.Update(res[i]);
  1331. }
  1332. }
  1333. }
  1334. #region 相同部分
  1335. public void TestRes(string sp, string result, string opname)
  1336. {
  1337. var res = _repository.GetFirstDefault<Information>(c => c.ProCode == sp && c.OperatorCode == opname);
  1338. if (res == null)
  1339. {
  1340. if (Order != null)
  1341. {
  1342. Application.Current.Dispatcher.Invoke(new Action(() =>
  1343. {
  1344. var productNew = new InformationNew
  1345. {
  1346. OperatorCode = opname,
  1347. ItemCode = "",
  1348. SpendTime = 0,
  1349. CreateTime = DateTime.Today,
  1350. ProType = proName,
  1351. ProNo = "",
  1352. ProCode = sp,
  1353. OrderNo = Order,
  1354. TestResult = result
  1355. };
  1356. var product = new Information()
  1357. {
  1358. CreateTime = productNew.CreateTime,
  1359. Id = Guid.NewGuid(),
  1360. OperatorCode = productNew.OperatorCode,
  1361. ItemCode = productNew.ItemCode,
  1362. SpendTime = productNew.SpendTime,
  1363. ProType = productNew.ProType,
  1364. ProNo = productNew.ProNo,
  1365. ProCode = productNew.ProCode,
  1366. OrderNo = productNew.OrderNo,
  1367. TestResult = productNew.TestResult
  1368. };
  1369. InforNew.Add(productNew);
  1370. _repository.Add(product);
  1371. }));
  1372. if (result == "OK")
  1373. {
  1374. try
  1375. {
  1376. DateTime dt = DateTime.Today;
  1377. var list = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);//查一个值
  1378. if (list != null)
  1379. {
  1380. list.OkS++;
  1381. _repository.Update(list);
  1382. }
  1383. var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == dt);
  1384. if (allnumbers != null)
  1385. {
  1386. allnumbers.OkA++;
  1387. _repository.Update(allnumbers);
  1388. }
  1389. }
  1390. catch (Exception ex)
  1391. {
  1392. WriteLog("TEST1:" + ex.Message, LogType.Error);
  1393. }
  1394. }
  1395. else
  1396. {
  1397. try
  1398. {
  1399. DateTime dt = DateTime.Today;
  1400. var list = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);//查一个值
  1401. if (list != null)
  1402. {
  1403. list.NgS++;
  1404. _repository.Update(list);
  1405. }
  1406. var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == dt);
  1407. if (allnumbers != null)
  1408. {
  1409. allnumbers.NgA++;
  1410. _repository.Update(allnumbers);
  1411. }
  1412. }
  1413. catch (Exception ex)
  1414. {
  1415. WriteLog("TEST2:" + ex.Message, LogType.Error);
  1416. }
  1417. }
  1418. }
  1419. //else
  1420. //{ WriteLog("订单编号没有设置", LogType.Warning); }
  1421. }
  1422. else
  1423. {
  1424. if (result == "OK")
  1425. {
  1426. var inf = _repository.GetFirstDefault<Information>(c => c.ProCode == sp && c.OperatorCode == opname && c.TestResult == "OK");
  1427. if (inf == null)
  1428. {
  1429. try
  1430. {
  1431. DateTime dt = DateTime.Today;
  1432. var list = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);//查一个值
  1433. if (list != null)
  1434. {
  1435. list.OkS++;
  1436. list.NgS--;
  1437. _repository.Update(list);
  1438. }
  1439. var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == dt);
  1440. if (allnumbers != null)
  1441. {
  1442. allnumbers.OkA++;
  1443. allnumbers.NgA--;
  1444. _repository.Update(allnumbers);
  1445. }
  1446. res.TestResult = result;
  1447. _repository.Update(res);
  1448. }
  1449. catch (Exception ex)
  1450. {
  1451. WriteLog("TEST3:" + ex.Message, LogType.Error);
  1452. }
  1453. }
  1454. }
  1455. else
  1456. {
  1457. var inf = _repository.GetFirstDefault<Information>(c => c.ProCode == sp && c.OperatorCode == opname && c.TestResult == "NG");
  1458. if (inf == null)
  1459. {
  1460. try
  1461. {
  1462. DateTime dt = DateTime.Today;
  1463. var list = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);//查一个值
  1464. if (list != null)
  1465. {
  1466. list.NgS++;
  1467. list.OkS--;
  1468. _repository.Update(list);
  1469. }
  1470. var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == dt);
  1471. if (allnumbers != null)
  1472. {
  1473. allnumbers.NgA++;
  1474. allnumbers.OkA--;
  1475. _repository.Update(allnumbers);
  1476. }
  1477. res.TestResult = result;
  1478. _repository.Update(res);
  1479. }
  1480. catch (Exception ex)
  1481. {
  1482. WriteLog("TEST4:" + ex.Message, LogType.Error);
  1483. }
  1484. }
  1485. }
  1486. }
  1487. }
  1488. #endregion
  1489. bool mybool = false;
  1490. private async void _timer_Elapsed1()
  1491. {
  1492. while (true)
  1493. {
  1494. try
  1495. {
  1496. if (Connected)
  1497. {
  1498. if (tcpNet.ReadInt(1500) == 1)
  1499. {
  1500. tcpNet.WriteInt(1500, 0);
  1501. }
  1502. //if (!mybool)
  1503. //{
  1504. // mybool = true;
  1505. // inovanceTcp.WriteDate("D1500", 0);
  1506. // //_logger.Information("{@Message}", "Timer:D1500_0");//后台log,会添加到数据中,不会显示到界面上
  1507. //}
  1508. //else
  1509. //{
  1510. // mybool = false;
  1511. // inovanceTcp.WriteDate("D1500", 1);
  1512. // //_logger.Information("{@Message}", "Timer:D1500_1");
  1513. //}
  1514. }
  1515. }
  1516. catch (Exception ex)
  1517. {
  1518. WriteLog("Timer:" + ex.Message, LogType.Error);
  1519. }
  1520. await Task.Delay(1000);
  1521. }
  1522. }
  1523. public void ProcessFinish(object sender, StateEventArgs e)
  1524. {
  1525. try
  1526. {
  1527. DateTime dt = DateTime.Today;
  1528. var list = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);//查一个值
  1529. if (list != null)
  1530. {
  1531. list.RealityS++;
  1532. _repository.Update(list);
  1533. }
  1534. var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == dt);
  1535. if (allnumbers != null)
  1536. {
  1537. allnumbers.RealityA++;
  1538. _repository.Update(allnumbers);
  1539. }
  1540. var d1 = tcpNet.ReadInt(1090);
  1541. var d2 = tcpNet.ReadInt(1091);
  1542. var d3 = tcpNet.ReadInt(1092);
  1543. soleNum = d1.ToString() + d2.ToString() + d3.ToString();
  1544. Quest(Order);
  1545. tcpNet.Write("1026.4", false);
  1546. }
  1547. catch (Exception ex)
  1548. {
  1549. WriteLog("ProcessFinish:" + ex.Message, LogType.Error);
  1550. }
  1551. }
  1552. string plannum; double plan;
  1553. List<string> fbarcode = new List<string>();
  1554. private void OrderEnter()
  1555. {
  1556. try
  1557. {
  1558. //if (string.IsNullOrWhiteSpace(SelectedOrderName))
  1559. //{
  1560. //}
  1561. //else
  1562. //{
  1563. fbarcode.Clear();
  1564. Quest(Order);
  1565. var customRepo = new CustomRepository();
  1566. try
  1567. {
  1568. var list = customRepo.GetFirstDefault<ICMO>(c => c.FBillNo == Order);
  1569. if (list != null)
  1570. {
  1571. plannum = list.FAuxQty.ToString();
  1572. plan = Math.Round(Convert.ToDouble(plannum));
  1573. WriteLog("切换订单成功");
  1574. }
  1575. else
  1576. {
  1577. WriteLog("订单错误", LogType.Error);
  1578. }
  1579. var t_pda = customRepo.GetAllQuery<t_PDABarCodeSign>(c => c.FBillNo == Order);
  1580. if (t_pda != null)
  1581. {
  1582. for (int i = 0; i < t_pda.Count; i++)
  1583. {
  1584. fbarcode.Add(t_pda[i].FBarCode);
  1585. tcpService.Send("192.168.10.15", "print:" + fbarcode[i]);
  1586. }
  1587. }
  1588. }
  1589. catch (Exception ex)
  1590. {
  1591. WriteLog("OrderEnter1:" + ex.Message, LogType.Error);
  1592. }
  1593. try
  1594. {
  1595. var ps = _repository.GetFirstDefault<ProStatus>(c => c.OrdNoS == Order);
  1596. if (ps == null)
  1597. {
  1598. var outp = new ProStatus()
  1599. {
  1600. Id = Guid.NewGuid(),
  1601. OrdNoS = Order,
  1602. PlanS = plan,
  1603. RealityS = 0,
  1604. OkS = 0,
  1605. NgS = 0,
  1606. ErrS = 0
  1607. };
  1608. _repository.Add(outp);
  1609. DateTime dt = DateTime.Today;
  1610. var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == dt);
  1611. if (allnumbers != null)
  1612. {
  1613. allnumbers.PlanA = allnumbers.PlanA + plan;
  1614. _repository.Update(allnumbers);
  1615. }
  1616. else
  1617. {
  1618. var al = new AllNumber()
  1619. {
  1620. Id = Guid.NewGuid(),
  1621. DateA = DateTime.Today,
  1622. PlanA = plan,
  1623. RealityA = 0,
  1624. OkA = 0,
  1625. NgA = 0,
  1626. ErrA = 0
  1627. };
  1628. _repository.Add(al);
  1629. }
  1630. }
  1631. }
  1632. catch (Exception ex)
  1633. {
  1634. WriteLog("OrderEnter2:" + ex.Message, LogType.Error);
  1635. }
  1636. //}
  1637. }
  1638. catch (Exception ex)
  1639. {
  1640. WriteLog("OrderEnter3:" + ex.Message, LogType.Error);
  1641. }
  1642. }
  1643. //public void ReadOrder()
  1644. //{
  1645. // var customRepo = new CustomRepository();
  1646. // try
  1647. // {
  1648. // DateTime max = DateTime.Today.AddDays(1);
  1649. // DateTime min = DateTime.Today.AddDays(-1);
  1650. // //var list = customRepo.GetAllQuery<ICMO>(c => c.FDate == DateTime.Today);
  1651. // var list = customRepo.GetAllQuery<ICMO>(c => c.FDate < max && c.FDate > min);
  1652. // if (list != null)
  1653. // {
  1654. // OrderNames = new ObservableCollection<string>();
  1655. // for (int i = 0; i < list.Count; i++)
  1656. // {
  1657. // OrderNames.Add(list[i].FBillNo);
  1658. // }
  1659. // }
  1660. // }
  1661. // catch (Exception ex)
  1662. // {
  1663. // WriteLog("ReadOrder:" + ex.Message, LogType.Error);
  1664. // }
  1665. //}
  1666. private void UploadOutWork()
  1667. {
  1668. var list = _repository.GetFirstDefault<OutofWork>(c => c.DateOutWork == DateTime.Today);
  1669. if (list != null)
  1670. {
  1671. list.DateOutWork = DateTime.Today;
  1672. list.Actual = ActPer;
  1673. list.FallIll = FallPer;
  1674. list.Absenteeism = AbsPer;
  1675. _repository.Update(list);
  1676. WriteLog("出勤信息上传成功");
  1677. }
  1678. else
  1679. {
  1680. var outwork = new OutofWork()
  1681. {
  1682. Id = Guid.NewGuid(),
  1683. DateOutWork = DateTime.Today,
  1684. Actual = ActPer,
  1685. FallIll = FallPer,
  1686. Absenteeism = AbsPer,
  1687. };
  1688. _repository.Add(outwork);
  1689. WriteLog("出勤信息上传成功");
  1690. }
  1691. }
  1692. private void UploadHouse()
  1693. {
  1694. var list = _repository.GetFirstDefault<House>(c => c.DateH == DateTime.Today);
  1695. if (list != null)
  1696. {
  1697. list.DateH = DateTime.Today;
  1698. list.LackH = LackHouse;
  1699. list.UsedH = UsedHouse;
  1700. list.TotalH = TotalHouse;
  1701. _repository.Update(list);
  1702. WriteLog("线边仓数据上传成功");
  1703. }
  1704. else
  1705. {
  1706. var houses = new House()
  1707. {
  1708. Id = Guid.NewGuid(),
  1709. DateH = DateTime.Today,
  1710. LackH = LackHouse,
  1711. UsedH = UsedHouse,
  1712. TotalH = TotalHouse,
  1713. };
  1714. _repository.Add(houses);
  1715. WriteLog("线边仓数据上传成功");
  1716. }
  1717. }
  1718. //void SwitchProduct()
  1719. //{
  1720. // SendToClient("Num1");
  1721. //}
  1722. //public void SendToClient(string id)
  1723. //{
  1724. // //tcpService.SocketClients.GetIds() 向所有id发送
  1725. // //foreach (var item in tcpService.SocketClients.GetIds())
  1726. // //{
  1727. // // if (string.IsNullOrWhiteSpace(SelectedConfigName))
  1728. // // {
  1729. // // tcpService.Send(item, "None");
  1730. // // WriteLog("发送:None");
  1731. // // return;
  1732. // // }
  1733. // // tcpService.Send(item, SelectedConfigName);
  1734. // // WriteLog("发送:" + SelectedConfigName);
  1735. // //}
  1736. // if (string.IsNullOrWhiteSpace(SelectedConfigName))
  1737. // {
  1738. // tcpService.Send(id, "None");
  1739. // WriteLog("发送:None");
  1740. // return;
  1741. // }
  1742. // tcpService.Send(id, SelectedConfigName);
  1743. // WriteLog("发送:" + SelectedConfigName);
  1744. //}
  1745. public void SendPro(string id, string name)
  1746. {
  1747. try
  1748. {
  1749. var ids = tcpService.SocketClients.GetIds();
  1750. foreach (var item in tcpService.SocketClients.GetClients())
  1751. {
  1752. if (item.IP == id)
  1753. {
  1754. item.Send("Type:" + name + ":" + id);
  1755. WriteLog("发送:" + name);
  1756. break;
  1757. }
  1758. }
  1759. //tcpService.Send(id, "Type:" + name + ":" + id);
  1760. //WriteLog("发送:" + name);
  1761. }
  1762. catch (Exception ex)
  1763. {
  1764. WriteLog("SendPro:" + ex.Message, LogType.Error);
  1765. }
  1766. }
  1767. string p1 = null, p2 = null, p3 = null, p4 = null, p5 = null, p6 = null, p7 = null,
  1768. p8 = null, p9 = null, p10 = null, p11 = null, p12 = null, p13 = null, p14 = null;
  1769. #region 工位
  1770. public void RecordOneMessage1(object sender, StateEventArgs e)//1
  1771. {
  1772. Application.Current.Dispatcher.Invoke(new Action(() =>
  1773. {
  1774. if (Order != null)
  1775. {
  1776. _logger.Information("{@Message}", "工位1触发");
  1777. //for (int i = 0; i < listMaterial1.Count; i++)
  1778. //{
  1779. // if (i == 0)
  1780. // {
  1781. // Material1 = listMaterial1[0];
  1782. // }
  1783. // else
  1784. // {
  1785. // Material1 = Material1 + "," + listMaterial1[i];
  1786. // }
  1787. //}
  1788. var spt = tcpNet.ReadInt(1003);
  1789. var d1 = tcpNet.ReadInt(1030);
  1790. var d2 = tcpNet.ReadInt(1031);
  1791. var d3 = tcpNet.ReadInt(1032);
  1792. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1793. _logger.Information("{@Message}", $"工位1_pno{pno}");
  1794. if (pno != p1)
  1795. {
  1796. var productNew = new InformationNew
  1797. {
  1798. OperatorCode = Operator1,
  1799. ItemCode = Material1,
  1800. SpendTime = spt / 10,
  1801. CreateTime = DateTime.Today,
  1802. ProType = proName,
  1803. ProNo = pno,
  1804. ProCode = "",
  1805. OrderNo = Order,
  1806. TestResult = ""
  1807. };
  1808. var product = new Information()
  1809. {
  1810. CreateTime = productNew.CreateTime,
  1811. Id = Guid.NewGuid(),
  1812. OperatorCode = productNew.OperatorCode,
  1813. ItemCode = productNew.ItemCode,
  1814. SpendTime = productNew.SpendTime,
  1815. ProType = productNew.ProType,
  1816. ProNo = productNew.ProNo,
  1817. ProCode = productNew.ProCode,
  1818. OrderNo = productNew.OrderNo,
  1819. TestResult = productNew.TestResult
  1820. };
  1821. InforNew.Add(productNew);
  1822. _repository.Add(product);
  1823. OperatorName(operName);
  1824. _logger.Information("{@Message}", $"工位1_Add");
  1825. //listMaterial1.Clear();
  1826. }
  1827. p1 = d1.ToString() + d2.ToString() + d3.ToString();
  1828. Thread.Sleep(200);
  1829. tcpNet.Write("1025.0", false);
  1830. _logger.Information("{@Message}", $"工位1_writefalse2");
  1831. }
  1832. tcpNet.Write("1025.0", false);
  1833. _logger.Information("{@Message}", $"工位1_writefalse3");
  1834. }));
  1835. }
  1836. public void RecordOneMessage2(object sender, StateEventArgs e)//2
  1837. {
  1838. Application.Current.Dispatcher.Invoke(new Action(() =>
  1839. {
  1840. if (Order != null)
  1841. {
  1842. _logger.Information("{@Message}", "工位2触发");
  1843. var spt = tcpNet.ReadInt(1004);
  1844. var d1 = tcpNet.ReadInt(1033);
  1845. var d2 = tcpNet.ReadInt(1034);
  1846. var d3 = tcpNet.ReadInt(1035);
  1847. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1848. _logger.Information("{@Message}", $"工位2_pno{pno}");
  1849. if (pno != p2)
  1850. {
  1851. var productNew = new InformationNew
  1852. {
  1853. OperatorCode = Operator2,
  1854. ItemCode = Material2,
  1855. SpendTime = spt / 10,
  1856. CreateTime = DateTime.Today,
  1857. ProType = proName,
  1858. ProNo = pno,
  1859. ProCode = "",
  1860. OrderNo = Order,
  1861. TestResult = ""
  1862. };
  1863. var product = new Information()
  1864. {
  1865. CreateTime = productNew.CreateTime,
  1866. Id = Guid.NewGuid(),
  1867. OperatorCode = productNew.OperatorCode,
  1868. ItemCode = productNew.ItemCode,
  1869. SpendTime = productNew.SpendTime,
  1870. ProType = productNew.ProType,
  1871. ProNo = productNew.ProNo,
  1872. ProCode = productNew.ProCode,
  1873. OrderNo = productNew.OrderNo,
  1874. TestResult = productNew.TestResult
  1875. };
  1876. _repository.Add(product);
  1877. InforNew.Add(productNew);
  1878. OperatorName(operName);
  1879. _logger.Information("{@Message}", $"工位2_Add");
  1880. }
  1881. p2 = d1.ToString() + d2.ToString() + d3.ToString();
  1882. Thread.Sleep(200);
  1883. tcpNet.Write("1025.1", false);
  1884. _logger.Information("{@Message}", $"工位2_writefalse2");
  1885. }
  1886. tcpNet.Write("1025.1", false);
  1887. _logger.Information("{@Message}", $"工位2_writefalse3");
  1888. }));
  1889. }
  1890. public void RecordOneMessage3(object sender, StateEventArgs e)//3
  1891. {
  1892. Application.Current.Dispatcher.Invoke(new Action(() =>
  1893. {
  1894. if (Order != null)
  1895. {
  1896. _logger.Information("{@Message}", "工位3触发");
  1897. var spt = tcpNet.ReadInt(1005);
  1898. var d1 = tcpNet.ReadInt(1036);
  1899. var d2 = tcpNet.ReadInt(1037);
  1900. var d3 = tcpNet.ReadInt(1038);
  1901. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1902. _logger.Information("{@Message}", $"工位3_pno{pno}");
  1903. if (pno != p3)
  1904. {
  1905. var productNew = new InformationNew
  1906. {
  1907. OperatorCode = Operator3,
  1908. ItemCode = Material3,
  1909. SpendTime = spt / 10,
  1910. CreateTime = DateTime.Today,
  1911. ProType = proName,
  1912. ProNo = pno,
  1913. ProCode = "",
  1914. OrderNo = Order,
  1915. TestResult = ""
  1916. };
  1917. var product = new Information()
  1918. {
  1919. CreateTime = productNew.CreateTime,
  1920. Id = Guid.NewGuid(),
  1921. OperatorCode = productNew.OperatorCode,
  1922. ItemCode = productNew.ItemCode,
  1923. SpendTime = productNew.SpendTime,
  1924. ProType = productNew.ProType,
  1925. ProNo = productNew.ProNo,
  1926. ProCode = productNew.ProCode,
  1927. OrderNo = productNew.OrderNo,
  1928. TestResult = productNew.TestResult
  1929. };
  1930. _repository.Add(product);
  1931. InforNew.Add(productNew);
  1932. OperatorName(operName);
  1933. _logger.Information("{@Message}", $"工位3_Add");
  1934. }
  1935. p3 = d1.ToString() + d2.ToString() + d3.ToString();
  1936. Thread.Sleep(200);
  1937. tcpNet.Write("1025.2", false);
  1938. _logger.Information("{@Message}", $"工位3_writefalse2");
  1939. }
  1940. tcpNet.Write("1025.2", false);
  1941. _logger.Information("{@Message}", $"工位3_writefalse3");
  1942. }));
  1943. }
  1944. public void RecordOneMessage4(object sender, StateEventArgs e)//4
  1945. {
  1946. Application.Current.Dispatcher.Invoke(new Action(() =>
  1947. {
  1948. if (Order != null)
  1949. {
  1950. _logger.Information("{@Message}", "工位4触发");
  1951. var spt = tcpNet.ReadInt(1006);
  1952. var d1 = tcpNet.ReadInt(1039);
  1953. var d2 = tcpNet.ReadInt(1040);
  1954. var d3 = tcpNet.ReadInt(1041);
  1955. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1956. _logger.Information("{@Message}", $"工位4_pno{pno}");
  1957. if (pno != p4)
  1958. {
  1959. var productNew = new InformationNew
  1960. {
  1961. OperatorCode = Operator4,
  1962. ItemCode = Material4,
  1963. SpendTime = spt / 10,
  1964. CreateTime = DateTime.Today,
  1965. ProType = proName,
  1966. ProNo = pno,
  1967. ProCode = "",
  1968. OrderNo = Order,
  1969. TestResult = ""
  1970. };
  1971. var product = new Information()
  1972. {
  1973. CreateTime = productNew.CreateTime,
  1974. Id = Guid.NewGuid(),
  1975. OperatorCode = productNew.OperatorCode,
  1976. ItemCode = productNew.ItemCode,
  1977. SpendTime = productNew.SpendTime,
  1978. ProType = productNew.ProType,
  1979. ProNo = productNew.ProNo,
  1980. ProCode = productNew.ProCode,
  1981. OrderNo = productNew.OrderNo,
  1982. TestResult = productNew.TestResult
  1983. };
  1984. _repository.Add(product);
  1985. InforNew.Add(productNew);
  1986. OperatorName(operName);
  1987. _logger.Information("{@Message}", $"工位4_Add");
  1988. }
  1989. p4 = d1.ToString() + d2.ToString() + d3.ToString();
  1990. Thread.Sleep(200);
  1991. tcpNet.Write("1025.3", false);
  1992. _logger.Information("{@Message}", $"工位4_writefalse2");
  1993. }
  1994. tcpNet.Write("1025.3", false);
  1995. _logger.Information("{@Message}", $"工位4_writefalse3");
  1996. }));
  1997. }
  1998. public void RecordOneMessage5(object sender, StateEventArgs e)//5
  1999. {
  2000. Application.Current.Dispatcher.Invoke(new Action(() =>
  2001. {
  2002. if (Order != null)
  2003. {
  2004. _logger.Information("{@Message}", "工位5触发");
  2005. var spt = tcpNet.ReadInt(1007);
  2006. var d1 = tcpNet.ReadInt(1042);
  2007. var d2 = tcpNet.ReadInt(1043);
  2008. var d3 = tcpNet.ReadInt(1044);
  2009. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2010. _logger.Information("{@Message}", $"工位5_pno{pno}");
  2011. if (pno != p5)
  2012. {
  2013. var productNew = new InformationNew
  2014. {
  2015. OperatorCode = Operator5,
  2016. ItemCode = Material5,
  2017. SpendTime = spt / 10,
  2018. CreateTime = DateTime.Today,
  2019. ProType = proName,
  2020. ProNo = pno,
  2021. ProCode = "",
  2022. OrderNo = Order,
  2023. TestResult = ""
  2024. };
  2025. var product = new Information()
  2026. {
  2027. CreateTime = productNew.CreateTime,
  2028. Id = Guid.NewGuid(),
  2029. OperatorCode = productNew.OperatorCode,
  2030. ItemCode = productNew.ItemCode,
  2031. SpendTime = productNew.SpendTime,
  2032. ProType = productNew.ProType,
  2033. ProNo = productNew.ProNo,
  2034. ProCode = productNew.ProCode,
  2035. OrderNo = productNew.OrderNo,
  2036. TestResult = productNew.TestResult
  2037. };
  2038. _repository.Add(product);
  2039. InforNew.Add(productNew);
  2040. OperatorName(operName);
  2041. _logger.Information("{@Message}", $"工位5_Add");
  2042. }
  2043. p5 = d1.ToString() + d2.ToString() + d3.ToString();
  2044. Thread.Sleep(200);
  2045. tcpNet.Write("1025.4", false);
  2046. _logger.Information("{@Message}", $"工位5_writefalse2");
  2047. }
  2048. tcpNet.Write("1025.4", false);
  2049. _logger.Information("{@Message}", $"工位5_writefalse3");
  2050. }));
  2051. }
  2052. public void RecordOneMessage6(object sender, StateEventArgs e)//6
  2053. {
  2054. Application.Current.Dispatcher.Invoke(new Action(() =>
  2055. {
  2056. if (Order != null)
  2057. {
  2058. _logger.Information("{@Message}", "工位6触发");
  2059. var spt = tcpNet.ReadInt(1008);
  2060. var d1 = tcpNet.ReadInt(1045);
  2061. var d2 = tcpNet.ReadInt(1046);
  2062. var d3 = tcpNet.ReadInt(1047);
  2063. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2064. _logger.Information("{@Message}", $"工位6_pno{pno}");
  2065. if (pno != p6)
  2066. {
  2067. var productNew = new InformationNew
  2068. {
  2069. OperatorCode = Operator6,
  2070. ItemCode = Material6,
  2071. SpendTime = spt / 10,
  2072. CreateTime = DateTime.Today,
  2073. ProType = proName,
  2074. ProNo = pno,
  2075. ProCode = "",
  2076. OrderNo = Order,
  2077. TestResult = ""
  2078. };
  2079. var product = new Information()
  2080. {
  2081. CreateTime = productNew.CreateTime,
  2082. Id = Guid.NewGuid(),
  2083. OperatorCode = productNew.OperatorCode,
  2084. ItemCode = productNew.ItemCode,
  2085. SpendTime = productNew.SpendTime,
  2086. ProType = productNew.ProType,
  2087. ProNo = productNew.ProNo,
  2088. ProCode = productNew.ProCode,
  2089. OrderNo = productNew.OrderNo,
  2090. TestResult = productNew.TestResult
  2091. };
  2092. _repository.Add(product);
  2093. InforNew.Add(productNew);
  2094. OperatorName(operName);
  2095. _logger.Information("{@Message}", $"工位6_Add");
  2096. }
  2097. p6 = d1.ToString() + d2.ToString() + d3.ToString();
  2098. Thread.Sleep(200);
  2099. tcpNet.Write("1025.5", false);
  2100. _logger.Information("{@Message}", $"工位6_writefalse2");
  2101. }
  2102. tcpNet.Write("1025.5", false);
  2103. _logger.Information("{@Message}", $"工位6_writefalse3");
  2104. }));
  2105. }
  2106. public void RecordOneMessage7(object sender, StateEventArgs e)//7
  2107. {
  2108. Application.Current.Dispatcher.Invoke(new Action(() =>
  2109. {
  2110. if (Order != null)
  2111. {
  2112. _logger.Information("{@Message}", "工位7触发");
  2113. var spt = tcpNet.ReadInt(1011);
  2114. var d1 = tcpNet.ReadInt(1048);
  2115. var d2 = tcpNet.ReadInt(1049);
  2116. var d3 = tcpNet.ReadInt(1050);
  2117. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2118. _logger.Information("{@Message}", $"工位7_pno{pno}");
  2119. if (pno != p7)
  2120. {
  2121. var productNew = new InformationNew
  2122. {
  2123. OperatorCode = Operator7,
  2124. ItemCode = Material7,
  2125. SpendTime = spt / 10,
  2126. CreateTime = DateTime.Today,
  2127. ProType = proName,
  2128. ProNo = pno,
  2129. ProCode = "",
  2130. OrderNo = Order,
  2131. TestResult = ""
  2132. };
  2133. var product = new Information()
  2134. {
  2135. CreateTime = productNew.CreateTime,
  2136. Id = Guid.NewGuid(),
  2137. OperatorCode = productNew.OperatorCode,
  2138. ItemCode = productNew.ItemCode,
  2139. SpendTime = productNew.SpendTime,
  2140. ProType = productNew.ProType,
  2141. ProNo = productNew.ProNo,
  2142. ProCode = productNew.ProCode,
  2143. OrderNo = productNew.OrderNo,
  2144. TestResult = productNew.TestResult
  2145. };
  2146. _repository.Add(product);
  2147. InforNew.Add(productNew);
  2148. OperatorName(operName);
  2149. _logger.Information("{@Message}", $"工位7_Add");
  2150. }
  2151. p7 = d1.ToString() + d2.ToString() + d3.ToString();
  2152. Thread.Sleep(200);
  2153. tcpNet.Write("1025.8", false);
  2154. _logger.Information("{@Message}", $"工位7_writefalse2");
  2155. }
  2156. tcpNet.Write("1025.8", false);
  2157. _logger.Information("{@Message}", $"工位7_writefalse3");
  2158. }));
  2159. }
  2160. public void RecordOneMessage8(object sender, StateEventArgs e)//8
  2161. {
  2162. Application.Current.Dispatcher.Invoke(new Action(() =>
  2163. {
  2164. if (Order != null)
  2165. {
  2166. _logger.Information("{@Message}", "工位8触发");
  2167. var spt = tcpNet.ReadInt(1012);
  2168. var d1 = tcpNet.ReadInt(1051);
  2169. var d2 = tcpNet.ReadInt(1052);
  2170. var d3 = tcpNet.ReadInt(1053);
  2171. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2172. _logger.Information("{@Message}", $"工位8_pno{pno}");
  2173. if (pno != p8)
  2174. {
  2175. var productNew = new InformationNew
  2176. {
  2177. OperatorCode = Operator8,
  2178. ItemCode = Material8,
  2179. SpendTime = spt / 10,
  2180. CreateTime = DateTime.Today,
  2181. ProType = proName,
  2182. ProNo = pno,
  2183. ProCode = "",
  2184. OrderNo = Order,
  2185. TestResult = ""
  2186. };
  2187. var product = new Information()
  2188. {
  2189. CreateTime = productNew.CreateTime,
  2190. Id = Guid.NewGuid(),
  2191. OperatorCode = productNew.OperatorCode,
  2192. ItemCode = productNew.ItemCode,
  2193. SpendTime = productNew.SpendTime,
  2194. ProType = productNew.ProType,
  2195. ProNo = productNew.ProNo,
  2196. ProCode = productNew.ProCode,
  2197. OrderNo = productNew.OrderNo,
  2198. TestResult = productNew.TestResult
  2199. };
  2200. _repository.Add(product);
  2201. InforNew.Add(productNew);
  2202. OperatorName(operName);
  2203. _logger.Information("{@Message}", $"工位8_Add");
  2204. }
  2205. p8 = d1.ToString() + d2.ToString() + d3.ToString();
  2206. Thread.Sleep(200);
  2207. tcpNet.Write("1025.9", false);
  2208. _logger.Information("{@Message}", $"工位8_writefalse2");
  2209. }
  2210. tcpNet.Write("1025.9", false);
  2211. _logger.Information("{@Message}", $"工位8_writefalse3");
  2212. }));
  2213. }
  2214. public void RecordOneMessage9(object sender, StateEventArgs e)//9
  2215. {
  2216. Application.Current.Dispatcher.Invoke(new Action(() =>
  2217. {
  2218. if (Order != null)
  2219. {
  2220. _logger.Information("{@Message}", "工位9触发");
  2221. var spt = tcpNet.ReadInt(1013);
  2222. var d1 = tcpNet.ReadInt(1054);
  2223. var d2 = tcpNet.ReadInt(1055);
  2224. var d3 = tcpNet.ReadInt(1056);
  2225. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2226. _logger.Information("{@Message}", $"工位9_pno{pno}");
  2227. if (pno != p9)
  2228. {
  2229. var productNew = new InformationNew
  2230. {
  2231. OperatorCode = Operator9,
  2232. ItemCode = Material9,
  2233. SpendTime = spt / 10,
  2234. CreateTime = DateTime.Today,
  2235. ProType = proName,
  2236. ProNo = pno,
  2237. ProCode = "",
  2238. OrderNo = Order,
  2239. TestResult = ""
  2240. };
  2241. var product = new Information()
  2242. {
  2243. CreateTime = productNew.CreateTime,
  2244. Id = Guid.NewGuid(),
  2245. OperatorCode = productNew.OperatorCode,
  2246. ItemCode = productNew.ItemCode,
  2247. SpendTime = productNew.SpendTime,
  2248. ProType = productNew.ProType,
  2249. ProNo = productNew.ProNo,
  2250. ProCode = productNew.ProCode,
  2251. OrderNo = productNew.OrderNo,
  2252. TestResult = productNew.TestResult
  2253. };
  2254. _repository.Add(product);
  2255. InforNew.Add(productNew);
  2256. OperatorName(operName);
  2257. _logger.Information("{@Message}", $"工位9_Add");
  2258. }
  2259. p9 = d1.ToString() + d2.ToString() + d3.ToString();
  2260. Thread.Sleep(200);
  2261. tcpNet.Write("1025.10", false);
  2262. _logger.Information("{@Message}", $"工位9_writefalse2");
  2263. }
  2264. tcpNet.Write("1025.10", false);
  2265. _logger.Information("{@Message}", $"工位9_writefalse3");
  2266. }));
  2267. }
  2268. public void RecordOneMessage10(object sender, StateEventArgs e)//10
  2269. {
  2270. Application.Current.Dispatcher.Invoke(new Action(() =>
  2271. {
  2272. if (Order != null)
  2273. {
  2274. _logger.Information("{@Message}", "工位10触发");
  2275. var spt = tcpNet.ReadInt(1014);
  2276. var d1 = tcpNet.ReadInt(1057);
  2277. var d2 = tcpNet.ReadInt(1058);
  2278. var d3 = tcpNet.ReadInt(1059);
  2279. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2280. _logger.Information("{@Message}", $"工位10_pno{pno}");
  2281. if (pno != p10)
  2282. {
  2283. var productNew = new InformationNew
  2284. {
  2285. OperatorCode = Operator10,
  2286. ItemCode = Material10,
  2287. SpendTime = spt / 10,
  2288. CreateTime = DateTime.Today,
  2289. ProType = proName,
  2290. ProNo = pno,
  2291. ProCode = "",
  2292. OrderNo = Order,
  2293. TestResult = ""
  2294. };
  2295. var product = new Information()
  2296. {
  2297. CreateTime = productNew.CreateTime,
  2298. Id = Guid.NewGuid(),
  2299. OperatorCode = productNew.OperatorCode,
  2300. ItemCode = productNew.ItemCode,
  2301. SpendTime = productNew.SpendTime,
  2302. ProType = productNew.ProType,
  2303. ProNo = productNew.ProNo,
  2304. ProCode = productNew.ProCode,
  2305. OrderNo = productNew.OrderNo,
  2306. TestResult = productNew.TestResult
  2307. };
  2308. _repository.Add(product);
  2309. InforNew.Add(productNew);
  2310. OperatorName(operName);
  2311. _logger.Information("{@Message}", $"工位10_Add");
  2312. }
  2313. p10 = d1.ToString() + d2.ToString() + d3.ToString();
  2314. Thread.Sleep(200);
  2315. tcpNet.Write("1025.11", false);
  2316. _logger.Information("{@Message}", $"工位10_writefalse2");
  2317. }
  2318. tcpNet.Write("1025.11", false);
  2319. _logger.Information("{@Message}", $"工位10_writefalse3");
  2320. }));
  2321. }
  2322. public void RecordOneMessage11(object sender, StateEventArgs e)//11
  2323. {
  2324. Application.Current.Dispatcher.Invoke(new Action(() =>
  2325. {
  2326. if (Order != null)
  2327. {
  2328. _logger.Information("{@Message}", "工位11触发");
  2329. var spt = tcpNet.ReadInt(1017);
  2330. var d1 = tcpNet.ReadInt(1060);
  2331. var d2 = tcpNet.ReadInt(1061);
  2332. var d3 = tcpNet.ReadInt(1062);
  2333. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2334. _logger.Information("{@Message}", $"工位11_pno{pno}");
  2335. if (pno != p11)
  2336. {
  2337. var productNew = new InformationNew
  2338. {
  2339. OperatorCode = Operator11,
  2340. ItemCode = Material11,
  2341. SpendTime = spt / 10,
  2342. CreateTime = DateTime.Today,
  2343. ProType = proName,
  2344. ProNo = pno,
  2345. ProCode = "",
  2346. OrderNo = Order,
  2347. TestResult = ""
  2348. };
  2349. var product = new Information()
  2350. {
  2351. CreateTime = productNew.CreateTime,
  2352. Id = Guid.NewGuid(),
  2353. OperatorCode = productNew.OperatorCode,
  2354. ItemCode = productNew.ItemCode,
  2355. SpendTime = productNew.SpendTime,
  2356. ProType = productNew.ProType,
  2357. ProNo = productNew.ProNo,
  2358. ProCode = productNew.ProCode,
  2359. OrderNo = productNew.OrderNo,
  2360. TestResult = productNew.TestResult
  2361. };
  2362. _repository.Add(product);
  2363. InforNew.Add(productNew);
  2364. OperatorName(operName);
  2365. _logger.Information("{@Message}", $"工位11_Add");
  2366. }
  2367. p11 = d1.ToString() + d2.ToString() + d3.ToString();
  2368. Thread.Sleep(200);
  2369. tcpNet.Write("1025.14", false);
  2370. _logger.Information("{@Message}", $"工位11_writefalse2");
  2371. }
  2372. tcpNet.Write("1025.14", false);
  2373. _logger.Information("{@Message}", $"工位11_writefalse3");
  2374. }));
  2375. }
  2376. public void RecordOneMessage12(object sender, StateEventArgs e)//12
  2377. {
  2378. Application.Current.Dispatcher.Invoke(new Action(() =>
  2379. {
  2380. if (Order != null)
  2381. {
  2382. _logger.Information("{@Message}", "工位12触发");
  2383. var spt = tcpNet.ReadInt(1018);
  2384. var d1 = tcpNet.ReadInt(1063);
  2385. var d2 = tcpNet.ReadInt(1064);
  2386. var d3 = tcpNet.ReadInt(1065);
  2387. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2388. _logger.Information("{@Message}", $"工位12_pno{pno}");
  2389. if (pno != p12)
  2390. {
  2391. var productNew = new InformationNew
  2392. {
  2393. OperatorCode = Operator12,
  2394. ItemCode = Material12,
  2395. SpendTime = spt / 10,
  2396. CreateTime = DateTime.Today,
  2397. ProType = proName,
  2398. ProNo = pno,
  2399. ProCode = "",
  2400. OrderNo = Order,
  2401. TestResult = ""
  2402. };
  2403. var product = new Information()
  2404. {
  2405. CreateTime = productNew.CreateTime,
  2406. Id = Guid.NewGuid(),
  2407. OperatorCode = productNew.OperatorCode,
  2408. ItemCode = productNew.ItemCode,
  2409. SpendTime = productNew.SpendTime,
  2410. ProType = productNew.ProType,
  2411. ProNo = productNew.ProNo,
  2412. ProCode = productNew.ProCode,
  2413. OrderNo = productNew.OrderNo,
  2414. TestResult = productNew.TestResult
  2415. };
  2416. _repository.Add(product);
  2417. InforNew.Add(productNew);
  2418. OperatorName(operName);
  2419. _logger.Information("{@Message}", $"工位12_Add");
  2420. }
  2421. p12 = d1.ToString() + d2.ToString() + d3.ToString();
  2422. Thread.Sleep(200);
  2423. tcpNet.Write("1025.15", false);
  2424. _logger.Information("{@Message}", $"工位12_writefalse2");
  2425. }
  2426. tcpNet.Write("1025.15", false);
  2427. _logger.Information("{@Message}", $"工位12_writefalse3");
  2428. }));
  2429. }
  2430. public void RecordOneMessage13(object sender, StateEventArgs e)//13
  2431. {
  2432. Application.Current.Dispatcher.Invoke(new Action(() =>
  2433. {
  2434. if (Order != null)
  2435. {
  2436. _logger.Information("{@Message}", "工位13触发");
  2437. var spt = tcpNet.ReadInt(1019);
  2438. var d1 = tcpNet.ReadInt(1066);
  2439. var d2 = tcpNet.ReadInt(1067);
  2440. var d3 = tcpNet.ReadInt(1068);
  2441. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2442. _logger.Information("{@Message}", $"工位13_pno{pno}");
  2443. if (pno != p13)
  2444. {
  2445. var productNew = new InformationNew
  2446. {
  2447. OperatorCode = Operator13,
  2448. ItemCode = Material13,
  2449. SpendTime = spt / 10,
  2450. CreateTime = DateTime.Today,
  2451. ProType = proName,
  2452. ProNo = pno,
  2453. ProCode = "",
  2454. OrderNo = Order,
  2455. TestResult = ""
  2456. };
  2457. var product = new Information()
  2458. {
  2459. CreateTime = productNew.CreateTime,
  2460. Id = Guid.NewGuid(),
  2461. OperatorCode = productNew.OperatorCode,
  2462. ItemCode = productNew.ItemCode,
  2463. SpendTime = productNew.SpendTime,
  2464. ProType = productNew.ProType,
  2465. ProNo = productNew.ProNo,
  2466. ProCode = productNew.ProCode,
  2467. OrderNo = productNew.OrderNo,
  2468. TestResult = productNew.TestResult
  2469. };
  2470. _repository.Add(product);
  2471. InforNew.Add(productNew);
  2472. OperatorName(operName);
  2473. _logger.Information("{@Message}", $"工位13_Add");
  2474. }
  2475. p13 = d1.ToString() + d2.ToString() + d3.ToString();
  2476. Thread.Sleep(200);
  2477. tcpNet.Write("1026.0", false);
  2478. _logger.Information("{@Message}", $"工位13_writefalse2");
  2479. }
  2480. tcpNet.Write("1026.0", false);
  2481. _logger.Information("{@Message}", $"工位13_writefalse3");
  2482. }));
  2483. }
  2484. public void RecordOneMessage14(object sender, StateEventArgs e)//14
  2485. {
  2486. Application.Current.Dispatcher.Invoke(new Action(() =>
  2487. {
  2488. try
  2489. {
  2490. if (Order != null)
  2491. {
  2492. _logger.Information("{@Message}", "工位14触发");
  2493. var spt = tcpNet.ReadInt(1020);
  2494. var d1 = tcpNet.ReadInt(1069);
  2495. var d2 = tcpNet.ReadInt(1070);
  2496. var d3 = tcpNet.ReadInt(1071);
  2497. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2498. _logger.Information("{@Message}", $"工位14_pno{pno}");
  2499. if (pno != p14)
  2500. {
  2501. var productNew = new InformationNew
  2502. {
  2503. OperatorCode = Operator14,
  2504. ItemCode = Material14,
  2505. SpendTime = spt / 10,
  2506. CreateTime = DateTime.Today,
  2507. ProType = proName,
  2508. ProNo = pno,
  2509. ProCode = "",
  2510. OrderNo = Order,
  2511. TestResult = ""
  2512. };
  2513. var product = new Information()
  2514. {
  2515. CreateTime = productNew.CreateTime,
  2516. Id = Guid.NewGuid(),
  2517. OperatorCode = productNew.OperatorCode,
  2518. ItemCode = productNew.ItemCode,
  2519. SpendTime = productNew.SpendTime,
  2520. ProType = productNew.ProType,
  2521. ProNo = productNew.ProNo,
  2522. ProCode = productNew.ProCode,
  2523. OrderNo = productNew.OrderNo,
  2524. TestResult = productNew.TestResult
  2525. };
  2526. _repository.Add(product);
  2527. InforNew.Add(productNew);
  2528. OperatorName(operName);
  2529. _logger.Information("{@Message}", $"工位14_Add");
  2530. }
  2531. p14 = d1.ToString() + d2.ToString() + d3.ToString();
  2532. Thread.Sleep(200);
  2533. tcpNet.Write("1026.1", false);
  2534. _logger.Information("{@Message}", $"工位14_writefalse2");
  2535. }
  2536. tcpNet.Write("1026.1", false);
  2537. _logger.Information("{@Message}", $"工位14_writefalse3");
  2538. }
  2539. catch (Exception ex)
  2540. {
  2541. WriteLog("RecordOneMessage14:" + ex.Message, LogType.Error);
  2542. }
  2543. }));
  2544. }
  2545. #endregion
  2546. public void OperatorName(string[] liststr)
  2547. {
  2548. _eventAggregator.GetEvent<OperatorNameEvent>().Publish(liststr);
  2549. }
  2550. public void Quest(string str)
  2551. {
  2552. _eventAggregator.GetEvent<QuestEvent>().Publish(str);
  2553. }
  2554. public void Alarm(Dictionary<string, string> plcsignal)
  2555. {
  2556. _eventAggregator.GetEvent<AlarmEvent>().Publish(plcsignal);//跨viewmodel发信息,Publish(发送的消息)
  2557. }
  2558. bool one = true;
  2559. string proName;
  2560. private void Timer_Elapsed()
  2561. {
  2562. while (true)
  2563. {
  2564. if (!Connected)
  2565. {
  2566. if (one)
  2567. {
  2568. WriteLog("plc连接异常", LogType.Error);
  2569. one = false;
  2570. }
  2571. continue;
  2572. }
  2573. try
  2574. {
  2575. if (one)
  2576. {
  2577. WriteLog("plc连接成功", LogType.Info);
  2578. one = false;
  2579. }
  2580. foreach (var item in SignalMapper)
  2581. {
  2582. //if (e.StartingAddress+e.Points.Length < item.Value)
  2583. //{
  2584. // continue;
  2585. //}
  2586. //var data = e.Points[item.Value];
  2587. //var value = inovanceTcp.Read(item.Value, 1);
  2588. var value = tcpNet.ReadBool(item.Value);
  2589. _stateService.ExecuteState(item.Key, value ? (ushort)1 : (ushort)0);
  2590. }
  2591. }
  2592. catch (ObjectDisposedException ex)
  2593. {
  2594. WriteLog("Timer_Elapsed:" + ex.Message, LogType.Error);
  2595. }
  2596. finally
  2597. {
  2598. Thread.Sleep(500);
  2599. }
  2600. }
  2601. }
  2602. int a = 0; bool b = true;
  2603. DateTime alarmtime;
  2604. private void Timer_Elapsed2()
  2605. {
  2606. while (true)
  2607. {
  2608. if (!Connected)
  2609. {
  2610. continue;
  2611. }
  2612. try
  2613. {
  2614. #region 报警
  2615. if (tcpNet.ReadInt(1130) != 0 || tcpNet.ReadInt(1131) != 0)
  2616. {
  2617. if (b)
  2618. {
  2619. alarmtime = DateTime.Now;
  2620. b = false;
  2621. }
  2622. }
  2623. else
  2624. {
  2625. try
  2626. {
  2627. if (!b)
  2628. {
  2629. string at = GetTime(alarmtime);
  2630. b = true;
  2631. var list = _repository.GetFirstDefault<DeviceStatus>(c => c.DateDS == DateTime.Today);
  2632. if (list != null)
  2633. {
  2634. list.AlarmTime = Convert.ToDouble(at);
  2635. _repository.Update(list);
  2636. }
  2637. else
  2638. {
  2639. var altime = new DeviceStatus()
  2640. {
  2641. Id = Guid.NewGuid(),
  2642. DateDS = DateTime.Today,
  2643. AlarmTime = Convert.ToDouble(at)
  2644. };
  2645. _repository.Add(altime);
  2646. }
  2647. }
  2648. }
  2649. catch (Exception)
  2650. {
  2651. }
  2652. }
  2653. var dictionary = new Dictionary<string, string>();
  2654. for (int i = 0; i < 31; i++)
  2655. {
  2656. var addrress = 1100 + i;
  2657. int ad = tcpNet.ReadInt((ushort)addrress);
  2658. if (ad != 0 && ad != -1)
  2659. {
  2660. dictionary.Add(addrress.ToString(), "报警");
  2661. }
  2662. else
  2663. {
  2664. dictionary.Add(addrress.ToString(), "正常");
  2665. }
  2666. }
  2667. for (int i = 0; i < 25; i++)
  2668. {
  2669. var addrress = (1141.15 + i).ToString();
  2670. if (tcpNet.ReadBool(addrress))
  2671. {
  2672. dictionary.Add(addrress, "缺料");
  2673. }
  2674. else
  2675. {
  2676. dictionary.Add(addrress, "正常");
  2677. }
  2678. }
  2679. for (int i = 0; i < 7; i++)
  2680. {
  2681. var addrress = (1166 + (double)i / 10).ToString("0.0");
  2682. if (tcpNet.ReadBool(addrress))
  2683. {
  2684. dictionary.Add(addrress, "缺料");
  2685. }
  2686. else
  2687. {
  2688. dictionary.Add(addrress, "正常");
  2689. }
  2690. }
  2691. Alarm(dictionary);
  2692. #endregion
  2693. }
  2694. catch (ObjectDisposedException ex)
  2695. {
  2696. WriteLog("Timer_Elapsed2:" + ex.Message, LogType.Error);
  2697. }
  2698. finally
  2699. {
  2700. Thread.Sleep(1000);
  2701. }
  2702. }
  2703. }
  2704. private void Timer_Elapsed3()
  2705. {
  2706. while (true)
  2707. {
  2708. if (!Connected)
  2709. {
  2710. continue;
  2711. }
  2712. try
  2713. {
  2714. //ReadOrder();
  2715. //切换产品
  2716. int type = tcpNet.ReadInt(1000);
  2717. if (a != type && type != -1)
  2718. {
  2719. Change();
  2720. }
  2721. if (type != -1)
  2722. {
  2723. a = type;
  2724. }
  2725. }
  2726. catch (ObjectDisposedException ex)
  2727. {
  2728. WriteLog("Timer_Elapsed3:" + ex.Message, LogType.Error);
  2729. }
  2730. finally
  2731. {
  2732. Thread.Sleep(1000);
  2733. }
  2734. }
  2735. }
  2736. //时间差
  2737. public static string GetTime(DateTime timeA)
  2738. {
  2739. //timeA 表示需要计算
  2740. DateTime timeB = DateTime.Now; //获取当前时间
  2741. TimeSpan ts = timeB - timeA; //计算时间差
  2742. string time = ts.TotalMinutes.ToString("0.00"); //将时间差转换为分钟
  2743. return time;
  2744. }
  2745. public void Change()
  2746. {
  2747. int type = tcpNet.ReadInt(1000);
  2748. switch (type)
  2749. {
  2750. case 1:
  2751. proName = "P60";
  2752. break;
  2753. case 2:
  2754. proName = "P70";
  2755. break;
  2756. case 3:
  2757. proName = "P80";
  2758. break;
  2759. case 4:
  2760. proName = "P90";
  2761. break;
  2762. case 5:
  2763. proName = "T29";
  2764. break;
  2765. case 6:
  2766. proName = "DH-88";
  2767. break;
  2768. case 7:
  2769. proName = "QL-1";
  2770. break;
  2771. }
  2772. if (tcpNet.ReadBool("1001.0"))
  2773. {
  2774. SendPro("192.168.10.1", proName);
  2775. }
  2776. if (tcpNet.ReadBool("1001.1"))
  2777. {
  2778. SendPro("192.168.10.2", proName);
  2779. }
  2780. if (tcpNet.ReadBool("1001.2"))
  2781. {
  2782. SendPro("192.168.10.3", proName);
  2783. }
  2784. if (tcpNet.ReadBool("1001.3"))
  2785. {
  2786. SendPro("192.168.10.4", proName);
  2787. }
  2788. if (tcpNet.ReadBool("1001.4"))
  2789. {
  2790. SendPro("192.168.10.5", proName);
  2791. }
  2792. if (tcpNet.ReadBool("1001.5"))
  2793. {
  2794. SendPro("192.168.10.6", proName);
  2795. }
  2796. if (tcpNet.ReadBool("1001.6"))
  2797. {
  2798. SendPro("192.168.10.7", proName);
  2799. }
  2800. if (tcpNet.ReadBool("1001.7"))
  2801. {
  2802. SendPro("192.168.10.8", proName);
  2803. }
  2804. if (tcpNet.ReadBool("1001.8"))
  2805. {
  2806. SendPro("192.168.10.9", proName);
  2807. }
  2808. if (tcpNet.ReadBool("1001.9"))
  2809. {
  2810. SendPro("192.168.10.10", proName);
  2811. }
  2812. if (tcpNet.ReadBool("1001.10"))
  2813. {
  2814. SendPro("192.168.10.11", proName);
  2815. }
  2816. if (tcpNet.ReadBool("1001.11"))
  2817. {
  2818. SendPro("192.168.10.12", proName);
  2819. }
  2820. if (tcpNet.ReadBool("1001.12"))
  2821. {
  2822. SendPro("192.168.10.13", proName);
  2823. }
  2824. if (tcpNet.ReadBool("1001.13"))
  2825. {
  2826. SendPro("192.168.10.14", proName);
  2827. }
  2828. if (tcpNet.ReadBool("1001.14"))
  2829. {
  2830. SendPro("192.168.10.15", proName);
  2831. }
  2832. if (tcpNet.ReadBool("1001.15"))
  2833. {
  2834. SendPro("192.168.10.16", proName);
  2835. }
  2836. if (tcpNet.ReadBool("1002.0"))
  2837. {
  2838. SendPro("192.168.10.17", proName);
  2839. }
  2840. if (tcpNet.ReadBool("1002.1"))
  2841. {
  2842. SendPro("192.168.10.18", proName);
  2843. }
  2844. }
  2845. public string SelectedConfigName { get; set; }
  2846. public ObservableCollection<string> ConfigNames { get; set; }
  2847. public WriteableBitmap QrImage { get; set; }
  2848. public void ReadConfig()
  2849. {
  2850. ConfigNames = new ObservableCollection<string>();
  2851. if (!Directory.Exists(@"d:\作业指导书\"))
  2852. {
  2853. return;
  2854. }
  2855. var files = Directory.GetFiles(@"d:\作业指导书\");
  2856. foreach (var item in files)
  2857. {
  2858. var file = new FileInfo(item);
  2859. if (file.Extension == ".json")
  2860. {
  2861. ConfigNames.Add(file.Name.Replace(file.Extension, ""));
  2862. }
  2863. }
  2864. }
  2865. public string ResWord(string s)
  2866. {
  2867. string[] str = s.Split(',');
  2868. List<string> words = new List<string>();
  2869. for (int i = 0; i < str.Length; i++)
  2870. {
  2871. if (str[i] != "")
  2872. {
  2873. words.Add(str[i]);
  2874. }
  2875. }
  2876. return string.Join(",", words.ToArray());
  2877. }
  2878. #region log
  2879. private void WriteLog(string message, LogType logType = LogType.Info, Exception exception = null)
  2880. {
  2881. if (exception != null)
  2882. {
  2883. _logger.Error("{@Message}", exception.ToString());
  2884. }
  2885. else
  2886. {
  2887. _logger.Information("{@Message}", message);
  2888. }
  2889. string singleLine = message.Trim();
  2890. string item = $"【{DateTime.Now:F}】 {singleLine}";
  2891. _eventAggregator.GetEvent<LogEvent>().Publish(new Tuple<LogType, string>(logType, item));
  2892. }
  2893. #endregion
  2894. #region 生成二维码
  2895. public void QRcode()
  2896. {
  2897. //GenerateQRCode(InQR);
  2898. //GenerateBarCode(InQR, 400, 150).Save("BarCode.png", System.Drawing.Imaging.ImageFormat.Png);
  2899. }
  2900. /// <summary>
  2901. /// 生成二维码图片
  2902. /// </summary>
  2903. public void GenerateQRCode(string qrCodeContent)
  2904. {
  2905. if (qrCodeContent != null)
  2906. {
  2907. using (var generator = new QRCodeGenerator())
  2908. {
  2909. // 创建二维码(并设置纠错能力最高级)
  2910. var createQrCode = generator.CreateQrCode(qrCodeContent, ECCLevel.H);
  2911. var skImageInfo = new SKImageInfo(300, 300);
  2912. // 创建SkiaSharp画布
  2913. using (var surface = SKSurface.Create(skImageInfo))
  2914. {
  2915. var canvas = surface.Canvas;
  2916. // 渲染二维码到画布
  2917. canvas.Render(createQrCode, skImageInfo.Width, skImageInfo.Height);
  2918. using var image = surface.Snapshot();// 获取画布快照
  2919. using var data = image.Encode(SKEncodedImageFormat.Png, 100);// 编码画布快照为PNG格式的数据
  2920. using (var stream = File.OpenWrite(@"MyQRCode.png"))
  2921. {
  2922. data.SaveTo(stream);// 将数据保存到文件流中,生成二维码图片
  2923. }
  2924. QrImage = image.ToWriteableBitmap();
  2925. }
  2926. WriteLog("二维码生成成功");
  2927. }
  2928. }
  2929. }
  2930. /// <summary>
  2931. /// 生成一维条形码
  2932. /// </summary>
  2933. /// <param name="text">内容</param>
  2934. /// <param name="width">宽度</param>
  2935. /// <param name="height">高度</param>
  2936. /// <returns></returns>
  2937. public Bitmap GenerateBarCode(string text, int width, int height)
  2938. {
  2939. BarcodeWriter writer = new BarcodeWriter();
  2940. //使用ITF 格式,不能被现在常用的支付宝、微信扫出来
  2941. //如果想生成可识别的可以使用 CODE_128 格式
  2942. writer.Format = BarcodeFormat.CODE_128;
  2943. EncodingOptions options = new EncodingOptions()
  2944. {
  2945. Width = width,
  2946. Height = height,
  2947. //GS1Format = false,
  2948. //PureBarcode = true,
  2949. Margin = 20
  2950. };
  2951. writer.Options = options;
  2952. BitMatrix bm = writer.Encode(text);
  2953. //Bitmap b = writer.Write(bm);
  2954. Bitmap b = writer.Write(text);
  2955. WriteLog("一维码生成成功");
  2956. return b;
  2957. }
  2958. #endregion
  2959. }
  2960. }