MainPageViewModel.cs 132 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077
  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.DateS == dt);//查一个值
  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.DateS == dt);//查一个值
  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.DateS == dt);//查一个值
  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.DateS == dt && 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.DateS == dt && 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.DateS == dt && 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.DateS == dt && 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.DateS == dt);//查一个值
  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. WriteLog("切换订单成功");
  1566. var customRepo = new CustomRepository();
  1567. try
  1568. {
  1569. var list = customRepo.GetFirstDefault<ICMO>(c => c.FBillNo == Order);
  1570. if (list != null)
  1571. {
  1572. plannum = list.FAuxQty.ToString();
  1573. plan = Math.Round(Convert.ToDouble(plannum));
  1574. }
  1575. var t_pda = customRepo.GetAllQuery<t_PDABarCodeSign>(c => c.FBillNo == Order);
  1576. if (t_pda != null)
  1577. {
  1578. for (int i = 0; i < t_pda.Count; i++)
  1579. {
  1580. fbarcode.Add(t_pda[i].FBarCode);
  1581. tcpService.Send("192.168.10.14", "print:" + fbarcode[i]);
  1582. }
  1583. }
  1584. }
  1585. catch (Exception ex)
  1586. {
  1587. WriteLog("OrderEnter1:" + ex.Message, LogType.Error);
  1588. }
  1589. var outp = new ProStatus()
  1590. {
  1591. Id = Guid.NewGuid(),
  1592. DateS = DateTime.Today,
  1593. OrdNoS = Order,
  1594. PlanS = plan,
  1595. RealityS = 0,
  1596. OkS = 0,
  1597. NgS = 0,
  1598. ErrS = 0
  1599. };
  1600. _repository.Add(outp);
  1601. try
  1602. {
  1603. DateTime dt = DateTime.Today;
  1604. var allnumbers = _repository.GetFirstDefault<AllNumber>(c => c.DateA == dt);
  1605. if (allnumbers != null)
  1606. {
  1607. allnumbers.PlanA = allnumbers.PlanA + plan;
  1608. _repository.Update(allnumbers);
  1609. }
  1610. else
  1611. {
  1612. var al = new AllNumber()
  1613. {
  1614. Id = Guid.NewGuid(),
  1615. DateA = DateTime.Today,
  1616. PlanA = plan,
  1617. RealityA = 0,
  1618. OkA = 0,
  1619. NgA = 0,
  1620. ErrA = 0
  1621. };
  1622. _repository.Add(al);
  1623. }
  1624. }
  1625. catch (Exception ex)
  1626. {
  1627. WriteLog("OrderEnter2:" + ex.Message, LogType.Error);
  1628. }
  1629. //}
  1630. }
  1631. catch (Exception ex)
  1632. {
  1633. WriteLog("OrderEnter3:" + ex.Message, LogType.Error);
  1634. }
  1635. }
  1636. //public void ReadOrder()
  1637. //{
  1638. // var customRepo = new CustomRepository();
  1639. // try
  1640. // {
  1641. // DateTime max = DateTime.Today.AddDays(1);
  1642. // DateTime min = DateTime.Today.AddDays(-1);
  1643. // //var list = customRepo.GetAllQuery<ICMO>(c => c.FDate == DateTime.Today);
  1644. // var list = customRepo.GetAllQuery<ICMO>(c => c.FDate < max && c.FDate > min);
  1645. // if (list != null)
  1646. // {
  1647. // OrderNames = new ObservableCollection<string>();
  1648. // for (int i = 0; i < list.Count; i++)
  1649. // {
  1650. // OrderNames.Add(list[i].FBillNo);
  1651. // }
  1652. // }
  1653. // }
  1654. // catch (Exception ex)
  1655. // {
  1656. // WriteLog("ReadOrder:" + ex.Message, LogType.Error);
  1657. // }
  1658. //}
  1659. private void UploadOutWork()
  1660. {
  1661. var list = _repository.GetFirstDefault<OutofWork>(c => c.DateOutWork == DateTime.Today);
  1662. if (list != null)
  1663. {
  1664. list.DateOutWork = DateTime.Today;
  1665. list.Actual = ActPer;
  1666. list.FallIll = FallPer;
  1667. list.Absenteeism = AbsPer;
  1668. _repository.Update(list);
  1669. WriteLog("出勤信息上传成功");
  1670. }
  1671. else
  1672. {
  1673. var outwork = new OutofWork()
  1674. {
  1675. Id = Guid.NewGuid(),
  1676. DateOutWork = DateTime.Today,
  1677. Actual = ActPer,
  1678. FallIll = FallPer,
  1679. Absenteeism = AbsPer,
  1680. };
  1681. _repository.Add(outwork);
  1682. WriteLog("出勤信息上传成功");
  1683. }
  1684. }
  1685. private void UploadHouse()
  1686. {
  1687. var list = _repository.GetFirstDefault<House>(c => c.DateH == DateTime.Today);
  1688. if (list != null)
  1689. {
  1690. list.DateH = DateTime.Today;
  1691. list.LackH = LackHouse;
  1692. list.UsedH = UsedHouse;
  1693. list.TotalH = TotalHouse;
  1694. _repository.Update(list);
  1695. WriteLog("线边仓数据上传成功");
  1696. }
  1697. else
  1698. {
  1699. var houses = new House()
  1700. {
  1701. Id = Guid.NewGuid(),
  1702. DateH = DateTime.Today,
  1703. LackH = LackHouse,
  1704. UsedH = UsedHouse,
  1705. TotalH = TotalHouse,
  1706. };
  1707. _repository.Add(houses);
  1708. WriteLog("线边仓数据上传成功");
  1709. }
  1710. }
  1711. //void SwitchProduct()
  1712. //{
  1713. // SendToClient("Num1");
  1714. //}
  1715. //public void SendToClient(string id)
  1716. //{
  1717. // //tcpService.SocketClients.GetIds() 向所有id发送
  1718. // //foreach (var item in tcpService.SocketClients.GetIds())
  1719. // //{
  1720. // // if (string.IsNullOrWhiteSpace(SelectedConfigName))
  1721. // // {
  1722. // // tcpService.Send(item, "None");
  1723. // // WriteLog("发送:None");
  1724. // // return;
  1725. // // }
  1726. // // tcpService.Send(item, SelectedConfigName);
  1727. // // WriteLog("发送:" + SelectedConfigName);
  1728. // //}
  1729. // if (string.IsNullOrWhiteSpace(SelectedConfigName))
  1730. // {
  1731. // tcpService.Send(id, "None");
  1732. // WriteLog("发送:None");
  1733. // return;
  1734. // }
  1735. // tcpService.Send(id, SelectedConfigName);
  1736. // WriteLog("发送:" + SelectedConfigName);
  1737. //}
  1738. public void SendPro(string id, string name)
  1739. {
  1740. try
  1741. {
  1742. var ids = tcpService.SocketClients.GetIds();
  1743. foreach (var item in tcpService.SocketClients.GetClients())
  1744. {
  1745. if (item.IP == id)
  1746. {
  1747. item.Send("Type:" + name + ":" + id);
  1748. WriteLog("发送:" + name);
  1749. break;
  1750. }
  1751. }
  1752. //tcpService.Send(id, "Type:" + name + ":" + id);
  1753. //WriteLog("发送:" + name);
  1754. }
  1755. catch (Exception ex)
  1756. {
  1757. WriteLog("SendPro:" + ex.Message, LogType.Error);
  1758. }
  1759. }
  1760. string p1 = null, p2 = null, p3 = null, p4 = null, p5 = null, p6 = null, p7 = null,
  1761. p8 = null, p9 = null, p10 = null, p11 = null, p12 = null, p13 = null, p14 = null;
  1762. #region 工位
  1763. public void RecordOneMessage1(object sender, StateEventArgs e)//1
  1764. {
  1765. Application.Current.Dispatcher.Invoke(new Action(() =>
  1766. {
  1767. if (Order != null)
  1768. {
  1769. _logger.Information("{@Message}", "工位1触发");
  1770. //for (int i = 0; i < listMaterial1.Count; i++)
  1771. //{
  1772. // if (i == 0)
  1773. // {
  1774. // Material1 = listMaterial1[0];
  1775. // }
  1776. // else
  1777. // {
  1778. // Material1 = Material1 + "," + listMaterial1[i];
  1779. // }
  1780. //}
  1781. var spt = tcpNet.ReadInt(1003);
  1782. var d1 = tcpNet.ReadInt(1030);
  1783. var d2 = tcpNet.ReadInt(1031);
  1784. var d3 = tcpNet.ReadInt(1032);
  1785. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1786. _logger.Information("{@Message}", $"工位1_pno{pno}");
  1787. if (pno != p1)
  1788. {
  1789. var productNew = new InformationNew
  1790. {
  1791. OperatorCode = Operator1,
  1792. ItemCode = Material1,
  1793. SpendTime = spt / 10,
  1794. CreateTime = DateTime.Today,
  1795. ProType = proName,
  1796. ProNo = pno,
  1797. ProCode = "",
  1798. OrderNo = Order,
  1799. TestResult = ""
  1800. };
  1801. var product = new Information()
  1802. {
  1803. CreateTime = productNew.CreateTime,
  1804. Id = Guid.NewGuid(),
  1805. OperatorCode = productNew.OperatorCode,
  1806. ItemCode = productNew.ItemCode,
  1807. SpendTime = productNew.SpendTime,
  1808. ProType = productNew.ProType,
  1809. ProNo = productNew.ProNo,
  1810. ProCode = productNew.ProCode,
  1811. OrderNo = productNew.OrderNo,
  1812. TestResult = productNew.TestResult
  1813. };
  1814. InforNew.Add(productNew);
  1815. _repository.Add(product);
  1816. OperatorName(operName);
  1817. _logger.Information("{@Message}", $"工位1_Add");
  1818. //listMaterial1.Clear();
  1819. }
  1820. p1 = d1.ToString() + d2.ToString() + d3.ToString();
  1821. Thread.Sleep(200);
  1822. tcpNet.Write("1025.0", false);
  1823. _logger.Information("{@Message}", $"工位1_writefalse2");
  1824. }
  1825. tcpNet.Write("1025.0", false);
  1826. _logger.Information("{@Message}", $"工位1_writefalse3");
  1827. }));
  1828. }
  1829. public void RecordOneMessage2(object sender, StateEventArgs e)//2
  1830. {
  1831. Application.Current.Dispatcher.Invoke(new Action(() =>
  1832. {
  1833. if (Order != null)
  1834. {
  1835. _logger.Information("{@Message}", "工位2触发");
  1836. var spt = tcpNet.ReadInt(1004);
  1837. var d1 = tcpNet.ReadInt(1033);
  1838. var d2 = tcpNet.ReadInt(1034);
  1839. var d3 = tcpNet.ReadInt(1035);
  1840. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1841. _logger.Information("{@Message}", $"工位2_pno{pno}");
  1842. if (pno != p2)
  1843. {
  1844. var productNew = new InformationNew
  1845. {
  1846. OperatorCode = Operator2,
  1847. ItemCode = Material2,
  1848. SpendTime = spt / 10,
  1849. CreateTime = DateTime.Today,
  1850. ProType = proName,
  1851. ProNo = pno,
  1852. ProCode = "",
  1853. OrderNo = Order,
  1854. TestResult = ""
  1855. };
  1856. var product = new Information()
  1857. {
  1858. CreateTime = productNew.CreateTime,
  1859. Id = Guid.NewGuid(),
  1860. OperatorCode = productNew.OperatorCode,
  1861. ItemCode = productNew.ItemCode,
  1862. SpendTime = productNew.SpendTime,
  1863. ProType = productNew.ProType,
  1864. ProNo = productNew.ProNo,
  1865. ProCode = productNew.ProCode,
  1866. OrderNo = productNew.OrderNo,
  1867. TestResult = productNew.TestResult
  1868. };
  1869. _repository.Add(product);
  1870. InforNew.Add(productNew);
  1871. OperatorName(operName);
  1872. _logger.Information("{@Message}", $"工位2_Add");
  1873. }
  1874. p2 = d1.ToString() + d2.ToString() + d3.ToString();
  1875. Thread.Sleep(200);
  1876. tcpNet.Write("1025.1", false);
  1877. _logger.Information("{@Message}", $"工位2_writefalse2");
  1878. }
  1879. tcpNet.Write("1025.1", false);
  1880. _logger.Information("{@Message}", $"工位2_writefalse3");
  1881. }));
  1882. }
  1883. public void RecordOneMessage3(object sender, StateEventArgs e)//3
  1884. {
  1885. Application.Current.Dispatcher.Invoke(new Action(() =>
  1886. {
  1887. if (Order != null)
  1888. {
  1889. _logger.Information("{@Message}", "工位3触发");
  1890. var spt = tcpNet.ReadInt(1005);
  1891. var d1 = tcpNet.ReadInt(1036);
  1892. var d2 = tcpNet.ReadInt(1037);
  1893. var d3 = tcpNet.ReadInt(1038);
  1894. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1895. _logger.Information("{@Message}", $"工位3_pno{pno}");
  1896. if (pno != p3)
  1897. {
  1898. var productNew = new InformationNew
  1899. {
  1900. OperatorCode = Operator3,
  1901. ItemCode = Material3,
  1902. SpendTime = spt / 10,
  1903. CreateTime = DateTime.Today,
  1904. ProType = proName,
  1905. ProNo = pno,
  1906. ProCode = "",
  1907. OrderNo = Order,
  1908. TestResult = ""
  1909. };
  1910. var product = new Information()
  1911. {
  1912. CreateTime = productNew.CreateTime,
  1913. Id = Guid.NewGuid(),
  1914. OperatorCode = productNew.OperatorCode,
  1915. ItemCode = productNew.ItemCode,
  1916. SpendTime = productNew.SpendTime,
  1917. ProType = productNew.ProType,
  1918. ProNo = productNew.ProNo,
  1919. ProCode = productNew.ProCode,
  1920. OrderNo = productNew.OrderNo,
  1921. TestResult = productNew.TestResult
  1922. };
  1923. _repository.Add(product);
  1924. InforNew.Add(productNew);
  1925. OperatorName(operName);
  1926. _logger.Information("{@Message}", $"工位3_Add");
  1927. }
  1928. p3 = d1.ToString() + d2.ToString() + d3.ToString();
  1929. Thread.Sleep(200);
  1930. tcpNet.Write("1025.2", false);
  1931. _logger.Information("{@Message}", $"工位3_writefalse2");
  1932. }
  1933. tcpNet.Write("1025.2", false);
  1934. _logger.Information("{@Message}", $"工位3_writefalse3");
  1935. }));
  1936. }
  1937. public void RecordOneMessage4(object sender, StateEventArgs e)//4
  1938. {
  1939. Application.Current.Dispatcher.Invoke(new Action(() =>
  1940. {
  1941. if (Order != null)
  1942. {
  1943. _logger.Information("{@Message}", "工位4触发");
  1944. var spt = tcpNet.ReadInt(1006);
  1945. var d1 = tcpNet.ReadInt(1039);
  1946. var d2 = tcpNet.ReadInt(1040);
  1947. var d3 = tcpNet.ReadInt(1041);
  1948. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  1949. _logger.Information("{@Message}", $"工位4_pno{pno}");
  1950. if (pno != p4)
  1951. {
  1952. var productNew = new InformationNew
  1953. {
  1954. OperatorCode = Operator4,
  1955. ItemCode = Material4,
  1956. SpendTime = spt / 10,
  1957. CreateTime = DateTime.Today,
  1958. ProType = proName,
  1959. ProNo = pno,
  1960. ProCode = "",
  1961. OrderNo = Order,
  1962. TestResult = ""
  1963. };
  1964. var product = new Information()
  1965. {
  1966. CreateTime = productNew.CreateTime,
  1967. Id = Guid.NewGuid(),
  1968. OperatorCode = productNew.OperatorCode,
  1969. ItemCode = productNew.ItemCode,
  1970. SpendTime = productNew.SpendTime,
  1971. ProType = productNew.ProType,
  1972. ProNo = productNew.ProNo,
  1973. ProCode = productNew.ProCode,
  1974. OrderNo = productNew.OrderNo,
  1975. TestResult = productNew.TestResult
  1976. };
  1977. _repository.Add(product);
  1978. InforNew.Add(productNew);
  1979. OperatorName(operName);
  1980. _logger.Information("{@Message}", $"工位4_Add");
  1981. }
  1982. p4 = d1.ToString() + d2.ToString() + d3.ToString();
  1983. Thread.Sleep(200);
  1984. tcpNet.Write("1025.3", false);
  1985. _logger.Information("{@Message}", $"工位4_writefalse2");
  1986. }
  1987. tcpNet.Write("1025.3", false);
  1988. _logger.Information("{@Message}", $"工位4_writefalse3");
  1989. }));
  1990. }
  1991. public void RecordOneMessage5(object sender, StateEventArgs e)//5
  1992. {
  1993. Application.Current.Dispatcher.Invoke(new Action(() =>
  1994. {
  1995. if (Order != null)
  1996. {
  1997. _logger.Information("{@Message}", "工位5触发");
  1998. var spt = tcpNet.ReadInt(1007);
  1999. var d1 = tcpNet.ReadInt(1042);
  2000. var d2 = tcpNet.ReadInt(1043);
  2001. var d3 = tcpNet.ReadInt(1044);
  2002. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2003. _logger.Information("{@Message}", $"工位5_pno{pno}");
  2004. if (pno != p5)
  2005. {
  2006. var productNew = new InformationNew
  2007. {
  2008. OperatorCode = Operator5,
  2009. ItemCode = Material5,
  2010. SpendTime = spt / 10,
  2011. CreateTime = DateTime.Today,
  2012. ProType = proName,
  2013. ProNo = pno,
  2014. ProCode = "",
  2015. OrderNo = Order,
  2016. TestResult = ""
  2017. };
  2018. var product = new Information()
  2019. {
  2020. CreateTime = productNew.CreateTime,
  2021. Id = Guid.NewGuid(),
  2022. OperatorCode = productNew.OperatorCode,
  2023. ItemCode = productNew.ItemCode,
  2024. SpendTime = productNew.SpendTime,
  2025. ProType = productNew.ProType,
  2026. ProNo = productNew.ProNo,
  2027. ProCode = productNew.ProCode,
  2028. OrderNo = productNew.OrderNo,
  2029. TestResult = productNew.TestResult
  2030. };
  2031. _repository.Add(product);
  2032. InforNew.Add(productNew);
  2033. OperatorName(operName);
  2034. _logger.Information("{@Message}", $"工位5_Add");
  2035. }
  2036. p5 = d1.ToString() + d2.ToString() + d3.ToString();
  2037. Thread.Sleep(200);
  2038. tcpNet.Write("1025.4", false);
  2039. _logger.Information("{@Message}", $"工位5_writefalse2");
  2040. }
  2041. tcpNet.Write("1025.4", false);
  2042. _logger.Information("{@Message}", $"工位5_writefalse3");
  2043. }));
  2044. }
  2045. public void RecordOneMessage6(object sender, StateEventArgs e)//6
  2046. {
  2047. Application.Current.Dispatcher.Invoke(new Action(() =>
  2048. {
  2049. if (Order != null)
  2050. {
  2051. _logger.Information("{@Message}", "工位6触发");
  2052. var spt = tcpNet.ReadInt(1008);
  2053. var d1 = tcpNet.ReadInt(1045);
  2054. var d2 = tcpNet.ReadInt(1046);
  2055. var d3 = tcpNet.ReadInt(1047);
  2056. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2057. _logger.Information("{@Message}", $"工位6_pno{pno}");
  2058. if (pno != p6)
  2059. {
  2060. var productNew = new InformationNew
  2061. {
  2062. OperatorCode = Operator6,
  2063. ItemCode = Material6,
  2064. SpendTime = spt / 10,
  2065. CreateTime = DateTime.Today,
  2066. ProType = proName,
  2067. ProNo = pno,
  2068. ProCode = "",
  2069. OrderNo = Order,
  2070. TestResult = ""
  2071. };
  2072. var product = new Information()
  2073. {
  2074. CreateTime = productNew.CreateTime,
  2075. Id = Guid.NewGuid(),
  2076. OperatorCode = productNew.OperatorCode,
  2077. ItemCode = productNew.ItemCode,
  2078. SpendTime = productNew.SpendTime,
  2079. ProType = productNew.ProType,
  2080. ProNo = productNew.ProNo,
  2081. ProCode = productNew.ProCode,
  2082. OrderNo = productNew.OrderNo,
  2083. TestResult = productNew.TestResult
  2084. };
  2085. _repository.Add(product);
  2086. InforNew.Add(productNew);
  2087. OperatorName(operName);
  2088. _logger.Information("{@Message}", $"工位6_Add");
  2089. }
  2090. p6 = d1.ToString() + d2.ToString() + d3.ToString();
  2091. Thread.Sleep(200);
  2092. tcpNet.Write("1025.5", false);
  2093. _logger.Information("{@Message}", $"工位6_writefalse2");
  2094. }
  2095. tcpNet.Write("1025.5", false);
  2096. _logger.Information("{@Message}", $"工位6_writefalse3");
  2097. }));
  2098. }
  2099. public void RecordOneMessage7(object sender, StateEventArgs e)//7
  2100. {
  2101. Application.Current.Dispatcher.Invoke(new Action(() =>
  2102. {
  2103. if (Order != null)
  2104. {
  2105. _logger.Information("{@Message}", "工位7触发");
  2106. var spt = tcpNet.ReadInt(1011);
  2107. var d1 = tcpNet.ReadInt(1048);
  2108. var d2 = tcpNet.ReadInt(1049);
  2109. var d3 = tcpNet.ReadInt(1050);
  2110. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2111. _logger.Information("{@Message}", $"工位7_pno{pno}");
  2112. if (pno != p7)
  2113. {
  2114. var productNew = new InformationNew
  2115. {
  2116. OperatorCode = Operator7,
  2117. ItemCode = Material7,
  2118. SpendTime = spt / 10,
  2119. CreateTime = DateTime.Today,
  2120. ProType = proName,
  2121. ProNo = pno,
  2122. ProCode = "",
  2123. OrderNo = Order,
  2124. TestResult = ""
  2125. };
  2126. var product = new Information()
  2127. {
  2128. CreateTime = productNew.CreateTime,
  2129. Id = Guid.NewGuid(),
  2130. OperatorCode = productNew.OperatorCode,
  2131. ItemCode = productNew.ItemCode,
  2132. SpendTime = productNew.SpendTime,
  2133. ProType = productNew.ProType,
  2134. ProNo = productNew.ProNo,
  2135. ProCode = productNew.ProCode,
  2136. OrderNo = productNew.OrderNo,
  2137. TestResult = productNew.TestResult
  2138. };
  2139. _repository.Add(product);
  2140. InforNew.Add(productNew);
  2141. OperatorName(operName);
  2142. _logger.Information("{@Message}", $"工位7_Add");
  2143. }
  2144. p7 = d1.ToString() + d2.ToString() + d3.ToString();
  2145. Thread.Sleep(200);
  2146. tcpNet.Write("1025.8", false);
  2147. _logger.Information("{@Message}", $"工位7_writefalse2");
  2148. }
  2149. tcpNet.Write("1025.8", false);
  2150. _logger.Information("{@Message}", $"工位7_writefalse3");
  2151. }));
  2152. }
  2153. public void RecordOneMessage8(object sender, StateEventArgs e)//8
  2154. {
  2155. Application.Current.Dispatcher.Invoke(new Action(() =>
  2156. {
  2157. if (Order != null)
  2158. {
  2159. _logger.Information("{@Message}", "工位8触发");
  2160. var spt = tcpNet.ReadInt(1012);
  2161. var d1 = tcpNet.ReadInt(1051);
  2162. var d2 = tcpNet.ReadInt(1052);
  2163. var d3 = tcpNet.ReadInt(1053);
  2164. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2165. _logger.Information("{@Message}", $"工位8_pno{pno}");
  2166. if (pno != p8)
  2167. {
  2168. var productNew = new InformationNew
  2169. {
  2170. OperatorCode = Operator8,
  2171. ItemCode = Material8,
  2172. SpendTime = spt / 10,
  2173. CreateTime = DateTime.Today,
  2174. ProType = proName,
  2175. ProNo = pno,
  2176. ProCode = "",
  2177. OrderNo = Order,
  2178. TestResult = ""
  2179. };
  2180. var product = new Information()
  2181. {
  2182. CreateTime = productNew.CreateTime,
  2183. Id = Guid.NewGuid(),
  2184. OperatorCode = productNew.OperatorCode,
  2185. ItemCode = productNew.ItemCode,
  2186. SpendTime = productNew.SpendTime,
  2187. ProType = productNew.ProType,
  2188. ProNo = productNew.ProNo,
  2189. ProCode = productNew.ProCode,
  2190. OrderNo = productNew.OrderNo,
  2191. TestResult = productNew.TestResult
  2192. };
  2193. _repository.Add(product);
  2194. InforNew.Add(productNew);
  2195. OperatorName(operName);
  2196. _logger.Information("{@Message}", $"工位8_Add");
  2197. }
  2198. p8 = d1.ToString() + d2.ToString() + d3.ToString();
  2199. Thread.Sleep(200);
  2200. tcpNet.Write("1025.9", false);
  2201. _logger.Information("{@Message}", $"工位8_writefalse2");
  2202. }
  2203. tcpNet.Write("1025.9", false);
  2204. _logger.Information("{@Message}", $"工位8_writefalse3");
  2205. }));
  2206. }
  2207. public void RecordOneMessage9(object sender, StateEventArgs e)//9
  2208. {
  2209. Application.Current.Dispatcher.Invoke(new Action(() =>
  2210. {
  2211. if (Order != null)
  2212. {
  2213. _logger.Information("{@Message}", "工位9触发");
  2214. var spt = tcpNet.ReadInt(1013);
  2215. var d1 = tcpNet.ReadInt(1054);
  2216. var d2 = tcpNet.ReadInt(1055);
  2217. var d3 = tcpNet.ReadInt(1056);
  2218. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2219. _logger.Information("{@Message}", $"工位9_pno{pno}");
  2220. if (pno != p9)
  2221. {
  2222. var productNew = new InformationNew
  2223. {
  2224. OperatorCode = Operator9,
  2225. ItemCode = Material9,
  2226. SpendTime = spt / 10,
  2227. CreateTime = DateTime.Today,
  2228. ProType = proName,
  2229. ProNo = pno,
  2230. ProCode = "",
  2231. OrderNo = Order,
  2232. TestResult = ""
  2233. };
  2234. var product = new Information()
  2235. {
  2236. CreateTime = productNew.CreateTime,
  2237. Id = Guid.NewGuid(),
  2238. OperatorCode = productNew.OperatorCode,
  2239. ItemCode = productNew.ItemCode,
  2240. SpendTime = productNew.SpendTime,
  2241. ProType = productNew.ProType,
  2242. ProNo = productNew.ProNo,
  2243. ProCode = productNew.ProCode,
  2244. OrderNo = productNew.OrderNo,
  2245. TestResult = productNew.TestResult
  2246. };
  2247. _repository.Add(product);
  2248. InforNew.Add(productNew);
  2249. OperatorName(operName);
  2250. _logger.Information("{@Message}", $"工位9_Add");
  2251. }
  2252. p9 = d1.ToString() + d2.ToString() + d3.ToString();
  2253. Thread.Sleep(200);
  2254. tcpNet.Write("1025.10", false);
  2255. _logger.Information("{@Message}", $"工位9_writefalse2");
  2256. }
  2257. tcpNet.Write("1025.10", false);
  2258. _logger.Information("{@Message}", $"工位9_writefalse3");
  2259. }));
  2260. }
  2261. public void RecordOneMessage10(object sender, StateEventArgs e)//10
  2262. {
  2263. Application.Current.Dispatcher.Invoke(new Action(() =>
  2264. {
  2265. if (Order != null)
  2266. {
  2267. _logger.Information("{@Message}", "工位10触发");
  2268. var spt = tcpNet.ReadInt(1014);
  2269. var d1 = tcpNet.ReadInt(1057);
  2270. var d2 = tcpNet.ReadInt(1058);
  2271. var d3 = tcpNet.ReadInt(1059);
  2272. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2273. _logger.Information("{@Message}", $"工位10_pno{pno}");
  2274. if (pno != p10)
  2275. {
  2276. var productNew = new InformationNew
  2277. {
  2278. OperatorCode = Operator10,
  2279. ItemCode = Material10,
  2280. SpendTime = spt / 10,
  2281. CreateTime = DateTime.Today,
  2282. ProType = proName,
  2283. ProNo = pno,
  2284. ProCode = "",
  2285. OrderNo = Order,
  2286. TestResult = ""
  2287. };
  2288. var product = new Information()
  2289. {
  2290. CreateTime = productNew.CreateTime,
  2291. Id = Guid.NewGuid(),
  2292. OperatorCode = productNew.OperatorCode,
  2293. ItemCode = productNew.ItemCode,
  2294. SpendTime = productNew.SpendTime,
  2295. ProType = productNew.ProType,
  2296. ProNo = productNew.ProNo,
  2297. ProCode = productNew.ProCode,
  2298. OrderNo = productNew.OrderNo,
  2299. TestResult = productNew.TestResult
  2300. };
  2301. _repository.Add(product);
  2302. InforNew.Add(productNew);
  2303. OperatorName(operName);
  2304. _logger.Information("{@Message}", $"工位10_Add");
  2305. }
  2306. p10 = d1.ToString() + d2.ToString() + d3.ToString();
  2307. Thread.Sleep(200);
  2308. tcpNet.Write("1025.11", false);
  2309. _logger.Information("{@Message}", $"工位10_writefalse2");
  2310. }
  2311. tcpNet.Write("1025.11", false);
  2312. _logger.Information("{@Message}", $"工位10_writefalse3");
  2313. }));
  2314. }
  2315. public void RecordOneMessage11(object sender, StateEventArgs e)//11
  2316. {
  2317. Application.Current.Dispatcher.Invoke(new Action(() =>
  2318. {
  2319. if (Order != null)
  2320. {
  2321. _logger.Information("{@Message}", "工位11触发");
  2322. var spt = tcpNet.ReadInt(1017);
  2323. var d1 = tcpNet.ReadInt(1060);
  2324. var d2 = tcpNet.ReadInt(1061);
  2325. var d3 = tcpNet.ReadInt(1062);
  2326. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2327. _logger.Information("{@Message}", $"工位11_pno{pno}");
  2328. if (pno != p11)
  2329. {
  2330. var productNew = new InformationNew
  2331. {
  2332. OperatorCode = Operator11,
  2333. ItemCode = Material11,
  2334. SpendTime = spt / 10,
  2335. CreateTime = DateTime.Today,
  2336. ProType = proName,
  2337. ProNo = pno,
  2338. ProCode = "",
  2339. OrderNo = Order,
  2340. TestResult = ""
  2341. };
  2342. var product = new Information()
  2343. {
  2344. CreateTime = productNew.CreateTime,
  2345. Id = Guid.NewGuid(),
  2346. OperatorCode = productNew.OperatorCode,
  2347. ItemCode = productNew.ItemCode,
  2348. SpendTime = productNew.SpendTime,
  2349. ProType = productNew.ProType,
  2350. ProNo = productNew.ProNo,
  2351. ProCode = productNew.ProCode,
  2352. OrderNo = productNew.OrderNo,
  2353. TestResult = productNew.TestResult
  2354. };
  2355. _repository.Add(product);
  2356. InforNew.Add(productNew);
  2357. OperatorName(operName);
  2358. _logger.Information("{@Message}", $"工位11_Add");
  2359. }
  2360. p11 = d1.ToString() + d2.ToString() + d3.ToString();
  2361. Thread.Sleep(200);
  2362. tcpNet.Write("1025.14", false);
  2363. _logger.Information("{@Message}", $"工位11_writefalse2");
  2364. }
  2365. tcpNet.Write("1025.14", false);
  2366. _logger.Information("{@Message}", $"工位11_writefalse3");
  2367. }));
  2368. }
  2369. public void RecordOneMessage12(object sender, StateEventArgs e)//12
  2370. {
  2371. Application.Current.Dispatcher.Invoke(new Action(() =>
  2372. {
  2373. if (Order != null)
  2374. {
  2375. _logger.Information("{@Message}", "工位12触发");
  2376. var spt = tcpNet.ReadInt(1018);
  2377. var d1 = tcpNet.ReadInt(1063);
  2378. var d2 = tcpNet.ReadInt(1064);
  2379. var d3 = tcpNet.ReadInt(1065);
  2380. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2381. _logger.Information("{@Message}", $"工位12_pno{pno}");
  2382. if (pno != p12)
  2383. {
  2384. var productNew = new InformationNew
  2385. {
  2386. OperatorCode = Operator12,
  2387. ItemCode = Material12,
  2388. SpendTime = spt / 10,
  2389. CreateTime = DateTime.Today,
  2390. ProType = proName,
  2391. ProNo = pno,
  2392. ProCode = "",
  2393. OrderNo = Order,
  2394. TestResult = ""
  2395. };
  2396. var product = new Information()
  2397. {
  2398. CreateTime = productNew.CreateTime,
  2399. Id = Guid.NewGuid(),
  2400. OperatorCode = productNew.OperatorCode,
  2401. ItemCode = productNew.ItemCode,
  2402. SpendTime = productNew.SpendTime,
  2403. ProType = productNew.ProType,
  2404. ProNo = productNew.ProNo,
  2405. ProCode = productNew.ProCode,
  2406. OrderNo = productNew.OrderNo,
  2407. TestResult = productNew.TestResult
  2408. };
  2409. _repository.Add(product);
  2410. InforNew.Add(productNew);
  2411. OperatorName(operName);
  2412. _logger.Information("{@Message}", $"工位12_Add");
  2413. }
  2414. p12 = d1.ToString() + d2.ToString() + d3.ToString();
  2415. Thread.Sleep(200);
  2416. tcpNet.Write("1025.15", false);
  2417. _logger.Information("{@Message}", $"工位12_writefalse2");
  2418. }
  2419. tcpNet.Write("1025.15", false);
  2420. _logger.Information("{@Message}", $"工位12_writefalse3");
  2421. }));
  2422. }
  2423. public void RecordOneMessage13(object sender, StateEventArgs e)//13
  2424. {
  2425. Application.Current.Dispatcher.Invoke(new Action(() =>
  2426. {
  2427. if (Order != null)
  2428. {
  2429. _logger.Information("{@Message}", "工位13触发");
  2430. var spt = tcpNet.ReadInt(1019);
  2431. var d1 = tcpNet.ReadInt(1066);
  2432. var d2 = tcpNet.ReadInt(1067);
  2433. var d3 = tcpNet.ReadInt(1068);
  2434. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2435. _logger.Information("{@Message}", $"工位13_pno{pno}");
  2436. if (pno != p13)
  2437. {
  2438. var productNew = new InformationNew
  2439. {
  2440. OperatorCode = Operator13,
  2441. ItemCode = Material13,
  2442. SpendTime = spt / 10,
  2443. CreateTime = DateTime.Today,
  2444. ProType = proName,
  2445. ProNo = pno,
  2446. ProCode = "",
  2447. OrderNo = Order,
  2448. TestResult = ""
  2449. };
  2450. var product = new Information()
  2451. {
  2452. CreateTime = productNew.CreateTime,
  2453. Id = Guid.NewGuid(),
  2454. OperatorCode = productNew.OperatorCode,
  2455. ItemCode = productNew.ItemCode,
  2456. SpendTime = productNew.SpendTime,
  2457. ProType = productNew.ProType,
  2458. ProNo = productNew.ProNo,
  2459. ProCode = productNew.ProCode,
  2460. OrderNo = productNew.OrderNo,
  2461. TestResult = productNew.TestResult
  2462. };
  2463. _repository.Add(product);
  2464. InforNew.Add(productNew);
  2465. OperatorName(operName);
  2466. _logger.Information("{@Message}", $"工位13_Add");
  2467. }
  2468. p13 = d1.ToString() + d2.ToString() + d3.ToString();
  2469. Thread.Sleep(200);
  2470. tcpNet.Write("1026.0", false);
  2471. _logger.Information("{@Message}", $"工位13_writefalse2");
  2472. }
  2473. tcpNet.Write("1026.0", false);
  2474. _logger.Information("{@Message}", $"工位13_writefalse3");
  2475. }));
  2476. }
  2477. public void RecordOneMessage14(object sender, StateEventArgs e)//14
  2478. {
  2479. Application.Current.Dispatcher.Invoke(new Action(() =>
  2480. {
  2481. try
  2482. {
  2483. if (Order != null)
  2484. {
  2485. _logger.Information("{@Message}", "工位14触发");
  2486. var spt = tcpNet.ReadInt(1020);
  2487. var d1 = tcpNet.ReadInt(1069);
  2488. var d2 = tcpNet.ReadInt(1070);
  2489. var d3 = tcpNet.ReadInt(1071);
  2490. var pno = d1.ToString() + d2.ToString() + d3.ToString();
  2491. _logger.Information("{@Message}", $"工位14_pno{pno}");
  2492. if (pno != p14)
  2493. {
  2494. var productNew = new InformationNew
  2495. {
  2496. OperatorCode = Operator14,
  2497. ItemCode = Material14,
  2498. SpendTime = spt / 10,
  2499. CreateTime = DateTime.Today,
  2500. ProType = proName,
  2501. ProNo = pno,
  2502. ProCode = "",
  2503. OrderNo = Order,
  2504. TestResult = ""
  2505. };
  2506. var product = new Information()
  2507. {
  2508. CreateTime = productNew.CreateTime,
  2509. Id = Guid.NewGuid(),
  2510. OperatorCode = productNew.OperatorCode,
  2511. ItemCode = productNew.ItemCode,
  2512. SpendTime = productNew.SpendTime,
  2513. ProType = productNew.ProType,
  2514. ProNo = productNew.ProNo,
  2515. ProCode = productNew.ProCode,
  2516. OrderNo = productNew.OrderNo,
  2517. TestResult = productNew.TestResult
  2518. };
  2519. _repository.Add(product);
  2520. InforNew.Add(productNew);
  2521. OperatorName(operName);
  2522. _logger.Information("{@Message}", $"工位14_Add");
  2523. }
  2524. p14 = d1.ToString() + d2.ToString() + d3.ToString();
  2525. Thread.Sleep(200);
  2526. tcpNet.Write("1026.1", false);
  2527. _logger.Information("{@Message}", $"工位14_writefalse2");
  2528. }
  2529. tcpNet.Write("1026.1", false);
  2530. _logger.Information("{@Message}", $"工位14_writefalse3");
  2531. }
  2532. catch (Exception ex)
  2533. {
  2534. WriteLog("RecordOneMessage14:" + ex.Message, LogType.Error);
  2535. }
  2536. }));
  2537. }
  2538. #endregion
  2539. public void OperatorName(string[] liststr)
  2540. {
  2541. _eventAggregator.GetEvent<OperatorNameEvent>().Publish(liststr);
  2542. }
  2543. public void Quest(string str)
  2544. {
  2545. _eventAggregator.GetEvent<QuestEvent>().Publish(str);
  2546. }
  2547. public void Alarm(Dictionary<string, string> plcsignal)
  2548. {
  2549. _eventAggregator.GetEvent<AlarmEvent>().Publish(plcsignal);//跨viewmodel发信息,Publish(发送的消息)
  2550. }
  2551. bool one = true;
  2552. string proName;
  2553. private void Timer_Elapsed()
  2554. {
  2555. while (true)
  2556. {
  2557. if (!Connected)
  2558. {
  2559. if (one)
  2560. {
  2561. WriteLog("plc连接异常", LogType.Error);
  2562. one = false;
  2563. }
  2564. continue;
  2565. }
  2566. try
  2567. {
  2568. if (one)
  2569. {
  2570. WriteLog("plc连接成功", LogType.Info);
  2571. one = false;
  2572. }
  2573. foreach (var item in SignalMapper)
  2574. {
  2575. //if (e.StartingAddress+e.Points.Length < item.Value)
  2576. //{
  2577. // continue;
  2578. //}
  2579. //var data = e.Points[item.Value];
  2580. //var value = inovanceTcp.Read(item.Value, 1);
  2581. var value = tcpNet.ReadBool(item.Value);
  2582. _stateService.ExecuteState(item.Key, value ? (ushort)1 : (ushort)0);
  2583. }
  2584. }
  2585. catch (ObjectDisposedException ex)
  2586. {
  2587. WriteLog("Timer_Elapsed:" + ex.Message, LogType.Error);
  2588. }
  2589. finally
  2590. {
  2591. Thread.Sleep(500);
  2592. }
  2593. }
  2594. }
  2595. int a = 0; bool b = true;
  2596. DateTime alarmtime;
  2597. private void Timer_Elapsed2()
  2598. {
  2599. while (true)
  2600. {
  2601. if (!Connected)
  2602. {
  2603. continue;
  2604. }
  2605. try
  2606. {
  2607. #region 报警
  2608. if (tcpNet.ReadInt(1130) != 0 || tcpNet.ReadInt(1131) != 0)
  2609. {
  2610. if (b)
  2611. {
  2612. alarmtime = DateTime.Now;
  2613. b = false;
  2614. }
  2615. }
  2616. else
  2617. {
  2618. try
  2619. {
  2620. if (!b)
  2621. {
  2622. string at = GetTime(alarmtime);
  2623. b = true;
  2624. var list = _repository.GetFirstDefault<DeviceStatus>(c => c.DateDS == DateTime.Today);
  2625. if (list != null)
  2626. {
  2627. list.AlarmTime = Convert.ToDouble(at);
  2628. _repository.Update(list);
  2629. }
  2630. else
  2631. {
  2632. var altime = new DeviceStatus()
  2633. {
  2634. Id = Guid.NewGuid(),
  2635. DateDS = DateTime.Today,
  2636. AlarmTime = Convert.ToDouble(at)
  2637. };
  2638. _repository.Add(altime);
  2639. }
  2640. }
  2641. }
  2642. catch (Exception)
  2643. {
  2644. }
  2645. }
  2646. var dictionary = new Dictionary<string, string>();
  2647. for (int i = 0; i < 31; i++)
  2648. {
  2649. var addrress = 1100 + i;
  2650. int ad = tcpNet.ReadInt((ushort)addrress);
  2651. if (ad != 0 && ad != -1)
  2652. {
  2653. dictionary.Add(addrress.ToString(), "报警");
  2654. }
  2655. else
  2656. {
  2657. dictionary.Add(addrress.ToString(), "正常");
  2658. }
  2659. }
  2660. for (int i = 0; i < 25; i++)
  2661. {
  2662. var addrress = (1141.15 + i).ToString();
  2663. if (tcpNet.ReadBool(addrress))
  2664. {
  2665. dictionary.Add(addrress, "缺料");
  2666. }
  2667. else
  2668. {
  2669. dictionary.Add(addrress, "正常");
  2670. }
  2671. }
  2672. for (int i = 0; i < 7; i++)
  2673. {
  2674. var addrress = (1166 + (double)i / 10).ToString("0.0");
  2675. if (tcpNet.ReadBool(addrress))
  2676. {
  2677. dictionary.Add(addrress, "缺料");
  2678. }
  2679. else
  2680. {
  2681. dictionary.Add(addrress, "正常");
  2682. }
  2683. }
  2684. Alarm(dictionary);
  2685. #endregion
  2686. }
  2687. catch (ObjectDisposedException ex)
  2688. {
  2689. WriteLog("Timer_Elapsed2:" + ex.Message, LogType.Error);
  2690. }
  2691. finally
  2692. {
  2693. Thread.Sleep(1000);
  2694. }
  2695. }
  2696. }
  2697. private void Timer_Elapsed3()
  2698. {
  2699. while (true)
  2700. {
  2701. if (!Connected)
  2702. {
  2703. continue;
  2704. }
  2705. try
  2706. {
  2707. //ReadOrder();
  2708. //切换产品
  2709. int type = tcpNet.ReadInt(1000);
  2710. if (a != type && type != -1)
  2711. {
  2712. Change();
  2713. }
  2714. if (type != -1)
  2715. {
  2716. a = type;
  2717. }
  2718. }
  2719. catch (ObjectDisposedException ex)
  2720. {
  2721. WriteLog("Timer_Elapsed3:" + ex.Message, LogType.Error);
  2722. }
  2723. finally
  2724. {
  2725. Thread.Sleep(1000);
  2726. }
  2727. }
  2728. }
  2729. //时间差
  2730. public static string GetTime(DateTime timeA)
  2731. {
  2732. //timeA 表示需要计算
  2733. DateTime timeB = DateTime.Now; //获取当前时间
  2734. TimeSpan ts = timeB - timeA; //计算时间差
  2735. string time = ts.TotalMinutes.ToString("0.00"); //将时间差转换为分钟
  2736. return time;
  2737. }
  2738. public void Change()
  2739. {
  2740. int type = tcpNet.ReadInt(1000);
  2741. switch (type)
  2742. {
  2743. case 1:
  2744. proName = "P60";
  2745. break;
  2746. case 2:
  2747. proName = "P70";
  2748. break;
  2749. case 3:
  2750. proName = "P80";
  2751. break;
  2752. case 4:
  2753. proName = "P90";
  2754. break;
  2755. case 5:
  2756. proName = "T29";
  2757. break;
  2758. case 6:
  2759. proName = "DH-88";
  2760. break;
  2761. case 7:
  2762. proName = "QL-1";
  2763. break;
  2764. }
  2765. if (tcpNet.ReadBool("1001.0"))
  2766. {
  2767. SendPro("192.168.10.1", proName);
  2768. }
  2769. if (tcpNet.ReadBool("1001.1"))
  2770. {
  2771. SendPro("192.168.10.2", proName);
  2772. }
  2773. if (tcpNet.ReadBool("1001.2"))
  2774. {
  2775. SendPro("192.168.10.3", proName);
  2776. }
  2777. if (tcpNet.ReadBool("1001.3"))
  2778. {
  2779. SendPro("192.168.10.4", proName);
  2780. }
  2781. if (tcpNet.ReadBool("1001.4"))
  2782. {
  2783. SendPro("192.168.10.5", proName);
  2784. }
  2785. if (tcpNet.ReadBool("1001.5"))
  2786. {
  2787. SendPro("192.168.10.6", proName);
  2788. }
  2789. if (tcpNet.ReadBool("1001.6"))
  2790. {
  2791. SendPro("192.168.10.7", proName);
  2792. }
  2793. if (tcpNet.ReadBool("1001.7"))
  2794. {
  2795. SendPro("192.168.10.8", proName);
  2796. }
  2797. if (tcpNet.ReadBool("1001.8"))
  2798. {
  2799. SendPro("192.168.10.9", proName);
  2800. }
  2801. if (tcpNet.ReadBool("1001.9"))
  2802. {
  2803. SendPro("192.168.10.10", proName);
  2804. }
  2805. if (tcpNet.ReadBool("1001.10"))
  2806. {
  2807. SendPro("192.168.10.11", proName);
  2808. }
  2809. if (tcpNet.ReadBool("1001.11"))
  2810. {
  2811. SendPro("192.168.10.12", proName);
  2812. }
  2813. if (tcpNet.ReadBool("1001.12"))
  2814. {
  2815. SendPro("192.168.10.13", proName);
  2816. }
  2817. if (tcpNet.ReadBool("1001.13"))
  2818. {
  2819. SendPro("192.168.10.14", proName);
  2820. }
  2821. if (tcpNet.ReadBool("1001.14"))
  2822. {
  2823. SendPro("192.168.10.15", proName);
  2824. }
  2825. if (tcpNet.ReadBool("1001.15"))
  2826. {
  2827. SendPro("192.168.10.16", proName);
  2828. }
  2829. if (tcpNet.ReadBool("1002.0"))
  2830. {
  2831. SendPro("192.168.10.17", proName);
  2832. }
  2833. if (tcpNet.ReadBool("1002.1"))
  2834. {
  2835. SendPro("192.168.10.18", proName);
  2836. }
  2837. }
  2838. public string SelectedConfigName { get; set; }
  2839. public ObservableCollection<string> ConfigNames { get; set; }
  2840. public WriteableBitmap QrImage { get; set; }
  2841. public void ReadConfig()
  2842. {
  2843. ConfigNames = new ObservableCollection<string>();
  2844. if (!Directory.Exists(@"d:\作业指导书\"))
  2845. {
  2846. return;
  2847. }
  2848. var files = Directory.GetFiles(@"d:\作业指导书\");
  2849. foreach (var item in files)
  2850. {
  2851. var file = new FileInfo(item);
  2852. if (file.Extension == ".json")
  2853. {
  2854. ConfigNames.Add(file.Name.Replace(file.Extension, ""));
  2855. }
  2856. }
  2857. }
  2858. public string ResWord(string s)
  2859. {
  2860. string[] str = s.Split(',');
  2861. List<string> words = new List<string>();
  2862. for (int i = 0; i < str.Length; i++)
  2863. {
  2864. if (str[i] != "")
  2865. {
  2866. words.Add(str[i]);
  2867. }
  2868. }
  2869. return string.Join(",", words.ToArray());
  2870. }
  2871. #region log
  2872. private void WriteLog(string message, LogType logType = LogType.Info, Exception exception = null)
  2873. {
  2874. if (exception != null)
  2875. {
  2876. _logger.Error("{@Message}", exception.ToString());
  2877. }
  2878. else
  2879. {
  2880. _logger.Information("{@Message}", message);
  2881. }
  2882. string singleLine = message.Trim();
  2883. string item = $"【{DateTime.Now:F}】 {singleLine}";
  2884. _eventAggregator.GetEvent<LogEvent>().Publish(new Tuple<LogType, string>(logType, item));
  2885. }
  2886. #endregion
  2887. #region 生成二维码
  2888. public void QRcode()
  2889. {
  2890. //GenerateQRCode(InQR);
  2891. //GenerateBarCode(InQR, 400, 150).Save("BarCode.png", System.Drawing.Imaging.ImageFormat.Png);
  2892. }
  2893. /// <summary>
  2894. /// 生成二维码图片
  2895. /// </summary>
  2896. public void GenerateQRCode(string qrCodeContent)
  2897. {
  2898. if (qrCodeContent != null)
  2899. {
  2900. using (var generator = new QRCodeGenerator())
  2901. {
  2902. // 创建二维码(并设置纠错能力最高级)
  2903. var createQrCode = generator.CreateQrCode(qrCodeContent, ECCLevel.H);
  2904. var skImageInfo = new SKImageInfo(300, 300);
  2905. // 创建SkiaSharp画布
  2906. using (var surface = SKSurface.Create(skImageInfo))
  2907. {
  2908. var canvas = surface.Canvas;
  2909. // 渲染二维码到画布
  2910. canvas.Render(createQrCode, skImageInfo.Width, skImageInfo.Height);
  2911. using var image = surface.Snapshot();// 获取画布快照
  2912. using var data = image.Encode(SKEncodedImageFormat.Png, 100);// 编码画布快照为PNG格式的数据
  2913. using (var stream = File.OpenWrite(@"MyQRCode.png"))
  2914. {
  2915. data.SaveTo(stream);// 将数据保存到文件流中,生成二维码图片
  2916. }
  2917. QrImage = image.ToWriteableBitmap();
  2918. }
  2919. WriteLog("二维码生成成功");
  2920. }
  2921. }
  2922. }
  2923. /// <summary>
  2924. /// 生成一维条形码
  2925. /// </summary>
  2926. /// <param name="text">内容</param>
  2927. /// <param name="width">宽度</param>
  2928. /// <param name="height">高度</param>
  2929. /// <returns></returns>
  2930. public Bitmap GenerateBarCode(string text, int width, int height)
  2931. {
  2932. BarcodeWriter writer = new BarcodeWriter();
  2933. //使用ITF 格式,不能被现在常用的支付宝、微信扫出来
  2934. //如果想生成可识别的可以使用 CODE_128 格式
  2935. writer.Format = BarcodeFormat.CODE_128;
  2936. EncodingOptions options = new EncodingOptions()
  2937. {
  2938. Width = width,
  2939. Height = height,
  2940. //GS1Format = false,
  2941. //PureBarcode = true,
  2942. Margin = 20
  2943. };
  2944. writer.Options = options;
  2945. BitMatrix bm = writer.Encode(text);
  2946. //Bitmap b = writer.Write(bm);
  2947. Bitmap b = writer.Write(text);
  2948. WriteLog("一维码生成成功");
  2949. return b;
  2950. }
  2951. #endregion
  2952. }
  2953. }