MainPageViewModel.cs 140 KB

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