MainPageViewModel.cs 138 KB

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