MainPageViewModel.cs 140 KB

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