MainPageViewModel.cs 132 KB

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