MainPageViewModel.cs 140 KB

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