MainPageViewModel.cs 135 KB

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