Management.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. 
  2. using DefaultEdit.Communication;
  3. using DefaultEdit.Log4xml;
  4. using DefaultEdit.Model;
  5. using Newtonsoft.Json.Linq;
  6. using NextTreatMesDemo.Models;
  7. using NextTreatMesDemo.Utils;
  8. using ObservableCollections;
  9. using Prism.Modularity;
  10. using Prism.Mvvm;
  11. using ScottPlot;
  12. using SqlSugar;
  13. using System;
  14. using System.Collections.Concurrent;
  15. using System.Collections.Generic;
  16. using System.Collections.ObjectModel;
  17. using System.Diagnostics;
  18. using System.IO;
  19. using System.Linq;
  20. using System.Text;
  21. using System.Threading;
  22. using System.Threading.Tasks;
  23. using System.Windows;
  24. namespace DefaultEdit.Core
  25. {
  26. public class Management : BindableBase
  27. {
  28. private CurentApplicationSettings _CurentApplicationSettings=new CurentApplicationSettings();
  29. private IServer _httpService = new MesServer();
  30. private S7PlcCommunicate s7PlcCommunicate;
  31. public event Action<string,bool> RuningToWorkEvent;
  32. public event Action ProduceDataToChangeEvent;
  33. private List<RfidInfo> _RfIDList=new List<RfidInfo>();
  34. public List<RfidInfo> RfIDList { get => _RfIDList; set => _RfIDList = value; }
  35. private ObservableCollection<RfidInfo> _RuningData=new ObservableCollection<RfidInfo>();
  36. public ObservableCollection<RfidInfo> RuningData { get => _RuningData; set => _RuningData = value; }
  37. private CurrConfig _currConfig = new CurrConfig();
  38. public CurrConfig CurrConfig { get => _currConfig; set { SetProperty(ref _currConfig, value); } }
  39. private DateTime _DateTimeNow;
  40. /// <summary>
  41. /// 当前时间
  42. /// </summary>
  43. public DateTime DateTimeNow
  44. {
  45. get { return _DateTimeNow; }
  46. set { SetProperty(ref _DateTimeNow, value); }
  47. }
  48. private ObservableCollection<string> _CurrStationRfid=new ObservableCollection<string>();
  49. public ObservableCollection<string> CurrStationRfid { get => _CurrStationRfid; set => _CurrStationRfid = value; }
  50. /// <summary>
  51. /// 用户Id(从MES接口内获取)
  52. /// </summary>
  53. private string _UserId = "";
  54. /// <summary>
  55. /// 用户名(从MES接口内获取)
  56. /// </summary>
  57. private string _UserName = "未登录";
  58. /// <summary>
  59. /// 用于记录后处理数据来打印小票
  60. /// </summary>
  61. public ObservableCollection<ProcessDataModel> processDataModels = new ObservableCollection<ProcessDataModel>();
  62. public double[] ProduceData = new double[]{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 };
  63. public IServer HttpService { get => _httpService; set { SetProperty(ref _httpService, value); } }
  64. public string UserId { get => _UserId; set { SetProperty(ref _UserId, value); } }
  65. public string UserName { get => _UserName; set { SetProperty(ref _UserName, value); } }
  66. public CurentApplicationSettings CurentApplicationSettings { get => _CurentApplicationSettings; set { SetProperty(ref _CurentApplicationSettings, value); } }
  67. //运行线程
  68. private Thread WorkThread;
  69. private Stopwatch[] stopwatchs = new Stopwatch[3];
  70. public Management()
  71. {
  72. stopwatchs[0] = new Stopwatch();
  73. stopwatchs[1] = new Stopwatch();
  74. stopwatchs[2] = new Stopwatch();
  75. for ( int i = 0; i < 6; i++ )
  76. {
  77. CurrStationRfid.Add("");
  78. }
  79. RuningToWorkEvent += Management_RuningToWorkEvent; ;
  80. WorkThread = new Thread(DataBridging);
  81. WorkThread.Name = "Plc读取";
  82. WorkThread.IsBackground = true;
  83. WorkThread.Start();
  84. }
  85. public void ConnectPlc()
  86. {
  87. s7PlcCommunicate = new S7PlcCommunicate(CurentApplicationSettings.PlcIP);
  88. s7PlcCommunicate.OpenPlc();
  89. }
  90. private void Management_RuningToWorkEvent(string key, bool value)
  91. {
  92. switch ( key )
  93. {
  94. case "1工位离心开始":
  95. if ( value )
  96. {
  97. stopwatchs[0].Restart();
  98. if ( RfIDList.Count != 0 )
  99. {
  100. int index= RfIDList.FindIndex(x => x.StationId == 1);
  101. if ( index != -1 )
  102. {
  103. RfIDList[ index ].StationId = 2;
  104. CurrStationRfid[ 1 ] = RfIDList[ index ].Rfid;
  105. LogHelper.Info(RfIDList[ index ].Rfid + " 1工位离心开始");
  106. }
  107. else
  108. {
  109. LogHelper.Info(" 1工位离心开始");
  110. }
  111. index = RfIDList.FindIndex(x => x.StationId == 1);
  112. if (index != -1)
  113. {
  114. RfIDList[index].StationId = 2;
  115. CurrStationRfid[2] = RfIDList[index].Rfid;
  116. LogHelper.Info(RfIDList[index].Rfid + " 1工位离心开始");
  117. }
  118. else
  119. {
  120. LogHelper.Info(" 1工位离心开始");
  121. }
  122. }
  123. }
  124. break;
  125. case "1工位离心完成":
  126. if ( value )
  127. {
  128. stopwatchs[0].Stop();
  129. if ( RfIDList.Count != 0 )
  130. {
  131. int index= RfIDList.FindIndex(x => x.StationId == 2);
  132. if ( index != -1 )
  133. {
  134. RfIDList[ index ].StationId = 3;
  135. LogHelper.Info(CurrStationRfid[ 1 ] + " 1工位离心完成");
  136. }
  137. else
  138. {
  139. LogHelper.Info(" 1工位离心完成");
  140. }
  141. index = RfIDList.FindIndex(x => x.StationId == 2);
  142. if (index != -1)
  143. {
  144. RfIDList[index].StationId = 3;
  145. LogHelper.Info(CurrStationRfid[2] + " 1工位离心完成");
  146. }
  147. else
  148. {
  149. LogHelper.Info(" 1工位离心完成");
  150. }
  151. CurrStationRfid[1] = "";
  152. CurrStationRfid[2] = "";
  153. }
  154. }
  155. break;
  156. case "2工位离心开始":
  157. if ( value )
  158. {
  159. stopwatchs[1].Restart();
  160. if ( RfIDList.Count != 0 )
  161. {
  162. int index= RfIDList.FindIndex(x => x.StationId == 3);
  163. if ( index != -1 )
  164. {
  165. RfIDList[ index ].StationId = 4;
  166. CurrStationRfid[ 3 ] = RfIDList[ index ].Rfid;
  167. LogHelper.Info(RfIDList[ index ].Rfid + " 2工位离心开始");
  168. }
  169. else
  170. {
  171. LogHelper.Info( " 2工位离心开始");
  172. }
  173. index = RfIDList.FindIndex(x => x.StationId == 1);
  174. if (index != -1)
  175. {
  176. RfIDList[index].StationId = 4;
  177. CurrStationRfid[4] = RfIDList[index].Rfid;
  178. LogHelper.Info(RfIDList[index].Rfid + " 2工位离心开始");
  179. }
  180. else
  181. {
  182. LogHelper.Info(" 2工位离心开始");
  183. }
  184. }
  185. }
  186. break;
  187. case "2工位离心完成":
  188. if ( value )
  189. {
  190. stopwatchs[1].Stop();
  191. if ( RfIDList.Count != 0 )
  192. {
  193. int index= RfIDList.FindIndex(x => x.StationId == 4);
  194. if ( index != -1 )
  195. {
  196. RfIDList[ index ].StationId = 5;
  197. LogHelper.Info(CurrStationRfid[ 3 ] + " 2工位离心完成");
  198. }
  199. else
  200. {
  201. LogHelper.Info(" 2工位离心完成");
  202. }
  203. index = RfIDList.FindIndex(x => x.StationId == 4);
  204. if (index != -1)
  205. {
  206. RfIDList[index].StationId = 5;
  207. LogHelper.Info(CurrStationRfid[4] + " 1工位离心完成");
  208. }
  209. else
  210. {
  211. LogHelper.Info(" 1工位离心完成");
  212. }
  213. CurrStationRfid[3] = "";
  214. CurrStationRfid[4] = "";
  215. }
  216. }
  217. break;
  218. case "脱模开始":
  219. if ( value )
  220. {
  221. LogHelper.Info(CurrConfig.Rfid + " 脱模开始");
  222. PlateInPlace(CurrConfig.Rfid);
  223. }
  224. break;
  225. case "脱模完成":
  226. if ( value )
  227. {
  228. LogHelper.Info(CurrConfig.Rfid + " 脱模完成");
  229. PrintInfo(processDataModels[0],"");
  230. }
  231. break;
  232. case "固化开始":
  233. if ( value )
  234. {
  235. stopwatchs[2].Restart();
  236. if ( RfIDList.Count != 0 )
  237. {
  238. int index= RfIDList.FindIndex(x => x.StationId ==5 );
  239. if ( index != -1 )
  240. {
  241. RfIDList[ index ].StationId = 6;
  242. CurrStationRfid[ 5 ] = RfIDList[ index ].Rfid;
  243. LogHelper.Info(RfIDList[ index ].Rfid + " 固化开始");
  244. }
  245. else
  246. {
  247. LogHelper.Info( " 固化开始");
  248. }
  249. index = RfIDList.FindIndex(x => x.StationId == 5);
  250. if (index != -1)
  251. {
  252. RfIDList[index].StationId = 6;
  253. CurrStationRfid[6] = RfIDList[index].Rfid;
  254. LogHelper.Info(RfIDList[index].Rfid + " 固化开始");
  255. }
  256. else
  257. {
  258. LogHelper.Info(" 固化开始");
  259. }
  260. }
  261. }
  262. break;
  263. case "固化完成":
  264. if ( value )
  265. {
  266. stopwatchs[2].Stop();
  267. if ( RfIDList.Count != 0 )
  268. {
  269. int index= RfIDList.FindIndex(x => x.StationId ==6 );
  270. if ( index != -1 )
  271. {
  272. RfIDList.RemoveAt(index);
  273. LogHelper.Info(RfIDList[ index ].Rfid + " 固化完成");
  274. }
  275. else
  276. {
  277. LogHelper.Info( " 固化完成");
  278. }
  279. index = RfIDList.FindIndex(x => x.StationId == 6);
  280. if (index != -1)
  281. {
  282. RfIDList.RemoveAt(index);
  283. LogHelper.Info(RfIDList[index].Rfid + " 固化完成");
  284. }
  285. else
  286. {
  287. LogHelper.Info(" 固化完成");
  288. }
  289. //CurrStationRfid[5] = RfIDList[index].Rfid;
  290. //CurrStationRfid[6] = RfIDList[index].Rfid;
  291. int hour= DateTime.Now.Hour;
  292. ProduceData[ hour ] = ProduceData[ hour ]+2;
  293. for ( int i = hour+1; i < ProduceData.Length; i++ )
  294. {
  295. ProduceData[ i ] = 0;
  296. }
  297. ProduceDataToChangeEvent?.Invoke();
  298. }
  299. }
  300. break;
  301. default:
  302. break;
  303. }
  304. }
  305. public void DataBridging()
  306. {
  307. ObservableDictionary<string,bool> BoolPairs=new ObservableDictionary<string, bool>();
  308. BoolPairs.Add("1工位离心开始", false);
  309. BoolPairs.Add("1工位离心完成", false);
  310. BoolPairs.Add("2工位离心开始", false);
  311. BoolPairs.Add("2工位离心完成", false);
  312. BoolPairs.Add("脱模开始", false);
  313. BoolPairs.Add("脱模完成", false);
  314. BoolPairs.Add("固化开始", false);
  315. BoolPairs.Add("固化完成", false);
  316. BoolPairs.CollectionChanged += BoolPairs_CollectionChanged;
  317. while ( true )
  318. {
  319. try
  320. {
  321. if (s7PlcCommunicate!=null&& s7PlcCommunicate.IsConnected )
  322. {
  323. byte []buff= s7PlcCommunicate.ReadByte(25, 780, 84);
  324. int actuallength=buff[53];
  325. byte[] buffsT = new byte[ actuallength ];
  326. Array.Copy(buff, 54, buffsT, 0, actuallength);
  327. CurrConfig.Rfid = Encoding.ASCII.GetString(buffsT);
  328. BoolPairs[ "1工位离心开始" ] = s7PlcCommunicate.GetBitAt(buff, 0, 0);
  329. BoolPairs[ "1工位离心完成" ] = s7PlcCommunicate.GetBitAt(buff, 0, 1);
  330. BoolPairs[ "2工位离心开始" ] = s7PlcCommunicate.GetBitAt(buff, 1, 0);
  331. BoolPairs[ "2工位离心完成" ] = s7PlcCommunicate.GetBitAt(buff, 1, 1);
  332. BoolPairs[ "脱模开始" ] = s7PlcCommunicate.GetBitAt(buff, 2, 0);
  333. BoolPairs[ "脱模完成" ] = s7PlcCommunicate.GetBitAt(buff, 2, 1);
  334. BoolPairs[ "固化开始" ] = s7PlcCommunicate.GetBitAt(buff, 3, 0);
  335. BoolPairs[ "固化完成" ] = s7PlcCommunicate.GetBitAt(buff, 3, 1);
  336. //固化压力 792.0
  337. CurrConfig.Pressure1 = s7PlcCommunicate.GetRealAt(buff, 12);
  338. CurrConfig.PTime1 = s7PlcCommunicate.GetTimeSpanAt(buff, 16);
  339. CurrConfig.Speed = s7PlcCommunicate.GetShortAt(buff, 32);
  340. CurrConfig.Speed2 = s7PlcCommunicate.GetShortAt(buff, 34);
  341. CurrConfig.RealSpeed = s7PlcCommunicate.GetRealAt(buff, 36);
  342. CurrConfig.RealSpeed2 = s7PlcCommunicate.GetRealAt(buff, 40);
  343. CurrConfig.Time = s7PlcCommunicate.GetTimeSpanAt(buff, 44);
  344. CurrConfig.Time2 = s7PlcCommunicate.GetTimeSpanAt(buff, 48);
  345. //CurrConfig.Power1_1 = s7PlcCommunicate.GetShortAt(buff, 20);
  346. //CurrConfig.Power1_2 = s7PlcCommunicate.GetShortAt(buff, 22);
  347. //CurrConfig.Power1_3 = s7PlcCommunicate.GetShortAt(buff, 24);
  348. //CurrConfig.Power1_4 = s7PlcCommunicate.GetShortAt(buff, 26);
  349. CurrConfig.Realtime = (float)(stopwatchs[0].ElapsedMilliseconds / 1000.0);
  350. CurrConfig.Realtime2 = (float)(stopwatchs[1].ElapsedMilliseconds / 1000.0);
  351. CurrConfig.Realtime3 = (float)(stopwatchs[2].ElapsedMilliseconds / 1000.0);
  352. for (int i = 0; i < stopwatchs.Length; i++)
  353. {
  354. if (stopwatchs[i].ElapsedMilliseconds / 1000.0 > 1000)
  355. {
  356. stopwatchs[i].Stop();
  357. }
  358. }
  359. }
  360. }
  361. catch
  362. {
  363. }
  364. Thread.Sleep(50);
  365. }
  366. }
  367. private void BoolPairs_CollectionChanged(in NotifyCollectionChangedEventArgs<KeyValuePair<string, bool>> e)
  368. {
  369. if ( e.NewItem.Value != e.OldItem.Value )
  370. {
  371. RuningToWorkEvent?.Invoke(e.OldItem.Key, e.NewItem.Value);
  372. }
  373. }
  374. private void Serial_ConnectionChanged(SerialCommunication arg1, bool arg2)
  375. {
  376. if ( arg2 )
  377. LogHelper.Info(arg1.PortName + ":已连接");
  378. if ( !arg2 )
  379. LogHelper.Info(arg1.PortName + ":断开连接");
  380. }
  381. private void Serial_DataReceived(SerialCommunication arg1, string arg2)
  382. {
  383. LogHelper.Info("收到" + arg1.PortName + $"消息:{arg2}");
  384. }
  385. /// <summary>
  386. /// 网板读取获取数据并上传记录
  387. /// </summary>
  388. public async Task PlateInPlace(string value)
  389. {
  390. var IsOK = true;
  391. try
  392. {
  393. if ( !string.IsNullOrEmpty(value) )
  394. {
  395. try
  396. {
  397. if ( value.Length != 8 )
  398. {
  399. return;
  400. }
  401. else
  402. {
  403. var boardId = value;
  404. string boardguid = Guid.NewGuid().ToString();
  405. var modelsinfo = "";
  406. var materialtype = "";
  407. var printdeviceId = "";
  408. var brand = "";
  409. var printTagProduct = "";
  410. var iskid = false;
  411. var ishaiwai = false;
  412. var isLarge = "无";
  413. var count = 0;
  414. var tip = "";
  415. var isoutline = false;
  416. var groupdata = _httpService.GetGroupItems(boardId, CurentApplicationSettings.DeviceId);
  417. if ( !groupdata.Success )
  418. {
  419. if ( groupdata.RawText.Contains("未点检") )
  420. {
  421. var s = MessageBox.Show("设备未点检,请点检后确认!", "提示", MessageBoxButton.OK);
  422. }
  423. LogHelper.MesInfo($"网板ID:{boardId}获取信息失败,Code:{( int ) groupdata.Code},原因:{groupdata.RawText}");
  424. isoutline = true;
  425. }
  426. else
  427. {
  428. if ( groupdata.Data.Count <= 0 )
  429. {
  430. LogHelper.MesInfo($"网板ID:{boardId}获取信息失败,Code:{( int ) groupdata.Code},原因:{groupdata.RawText}");
  431. isoutline = true;
  432. }
  433. }
  434. if ( !isoutline )
  435. {
  436. ///上传后处理记录
  437. var result = UpdateRecord(boardId);
  438. if ( !string.IsNullOrEmpty(result) )
  439. {
  440. LogHelper.MesInfo($"上传记录失败,{result}!");
  441. var boxresult = MessageBox.Show($"{result}(是:放回;否:重试)", "提示", MessageBoxButton.YesNo);
  442. if ( boxresult == MessageBoxResult.Yes )
  443. {
  444. IsOK = false;
  445. return;
  446. }
  447. }
  448. ///读取网板内的牙模的信息(方便打印在小票上),如果读取失败就读取下一个牙模,读取成功就跳出循环
  449. for ( int i = 0; i < 10; i++ )
  450. {
  451. try
  452. {
  453. modelsinfo = "";
  454. count = groupdata.Data.Count;
  455. var Id = groupdata.Data[groupdata.Data.Count - i].itemId;
  456. var infos = _httpService.GetModels(Id, CurentApplicationSettings.DeviceId);
  457. if ( infos.Success )
  458. {
  459. modelsinfo = infos.Data.uvcuringReleaseBatch + " " + infos.Data.alignerSpec.material + "-" + infos.Data.alignerSpec.thickness;
  460. if ( infos.Data.order.is_expedited == "1" || infos.Data.remade || infos.Data.produceType == "R" )
  461. {
  462. modelsinfo = modelsinfo + "\r\n";
  463. if ( infos.Data.order.is_expedited == "1" )
  464. {
  465. modelsinfo = modelsinfo + " 加急";
  466. }
  467. if ( infos.Data.remade )
  468. {
  469. modelsinfo = modelsinfo + " 返工";
  470. }
  471. if ( infos.Data.produceType == "R" )
  472. {
  473. modelsinfo = modelsinfo + " 保持器";
  474. }
  475. }
  476. iskid = infos.Data.isKid;
  477. ishaiwai = infos.Data.order.country.Contains("中国") ? false : true;
  478. if ( infos.Data.processParameters != null )
  479. {
  480. var carrierf = infos.Data.processParameters.FirstOrDefault(x => x.key == "carrier");
  481. if ( carrierf != null )
  482. {
  483. isLarge = carrierf.value == "small" ? "小载具" : "大载具";
  484. }
  485. }
  486. var record = _httpService.GetProductionRecord(Id);
  487. if ( record.Success )
  488. {
  489. printdeviceId = record.Data.First().deviceId;
  490. if ( record.Data.First().description.FirstOrDefault(x => x.key == "printTaskId") != null )
  491. {
  492. var taskId = record.Data.First().description.FirstOrDefault(x => x.key == "printTaskId").value;
  493. var taskinfo = _httpService.GetPrintTask(taskId);
  494. if ( taskinfo.Success )
  495. {
  496. materialtype = taskinfo.Data.description.FirstOrDefault(x => x.key == "filmType") != null ? taskinfo.Data.description.FirstOrDefault(x => x.key == "filmType").value : "";
  497. printTagProduct = taskinfo.Data.description.FirstOrDefault(x => x.key == "printTagProduct") != null ? taskinfo.Data.description.FirstOrDefault(x => x.key == "printTagProduct").value : "";
  498. brand = taskinfo.Data.description.FirstOrDefault(x => x.key == "productOfProduce") != null ? taskinfo.Data.description.FirstOrDefault(x => x.key == "productOfProduce").value : "";
  499. break;
  500. }
  501. }
  502. }
  503. }
  504. }
  505. catch ( Exception e )
  506. {
  507. LogHelper.Error("读取网板内牙模信息异常:" + e.ToString());
  508. }
  509. }
  510. }
  511. else
  512. {
  513. LogHelper.MesInfo($"网板{value}获取数据异常,不上传记录");
  514. modelsinfo = "异常";
  515. materialtype = "异常";
  516. printTagProduct = "异常";
  517. printdeviceId = "异常";
  518. brand = "异常";
  519. }
  520. ///将生产信息记录下,用于在打印完成时打印小票
  521. App.Current.Dispatcher.Invoke(( System.Action ) delegate
  522. {
  523. //添加记录
  524. processDataModels.Add(new ProcessDataModel()
  525. {
  526. BoardId = boardId,
  527. ModelsInfo = modelsinfo,
  528. StartTime = DateTime.Now.ToString("HH:mm:ss"),
  529. State = ProcessState.入料中,
  530. BoardGuid = boardguid,
  531. stopwatch = new System.Diagnostics.Stopwatch(),
  532. MaterialType = materialtype,
  533. PrintTagProduct = printTagProduct,
  534. PrintDeviceId = printdeviceId,
  535. IsKid = iskid,
  536. Tip = tip,
  537. IsOverSea = ishaiwai,
  538. IsLarge = isLarge,
  539. Brand = brand,
  540. Count = count,
  541. });
  542. if ( processDataModels.Count > 10 )
  543. {
  544. processDataModels.RemoveAt(0);
  545. }
  546. RfidInfo rfidInfo= new RfidInfo() { Rfid = value, StationId = 1, ModelsInfo=modelsinfo, State="入料中", StartTime=DateTime.Now };
  547. if ( RfIDList.Find(x=>x.Rfid==value)==null )
  548. {
  549. RfIDList.Add(rfidInfo);
  550. RuningData.Add(rfidInfo);
  551. }
  552. });
  553. }
  554. }
  555. catch ( Exception e )
  556. {
  557. LogHelper.Error("网板读取获取数据异常,原因:" + e.ToString());
  558. }
  559. }
  560. else
  561. {
  562. LogHelper.Info("未读取到网板编号");
  563. //WriteInfo($"未读取到网板编号");
  564. }
  565. }
  566. catch
  567. {
  568. }
  569. finally
  570. {
  571. }
  572. }
  573. /// <summary>
  574. /// 上传生产记录
  575. /// </summary>
  576. /// <param name="RfidId">从扫码枪获取的网板Id</param>
  577. /// <returns></returns>
  578. public string UpdateRecord(string RfidId)
  579. {
  580. try
  581. {
  582. Rt_ProductionRecordDto rt_ProductionRecord = new Rt_ProductionRecordDto()
  583. {
  584. userId = UserId,///用户Id
  585. creationTime = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fffzzz"),///生产时间
  586. deviceId = CurentApplicationSettings.DeviceId,///设备编号
  587. productionType = "UVcuringNextTreat",///生产工序,固定不变
  588. description = new List<DescriptionItem>()
  589. {
  590. ///从扫码枪获取的网板Id
  591. new DescriptionItem(){ key="containerId",value=RfidId},
  592. //后处理配方(根据设备不同参数也不同,具体需要上传什么参数要具体咨询下现场的工艺人员(程朋))
  593. new DescriptionItem(){ key="CentrifugalTime1",value="240"},
  594. new DescriptionItem(){ key="CentrifugalTime2",value="240"},
  595. new DescriptionItem(){ key="LightSolidifiedTime",value="240"},
  596. }
  597. };
  598. var recordData = _httpService.PostRecord(rt_ProductionRecord);
  599. if ( recordData.Success )
  600. {
  601. LogHelper.MesInfo($"网板ID:{RfidId}上传记录成功");
  602. return "";
  603. }
  604. else
  605. {
  606. LogHelper.MesInfo($"网板ID:{RfidId}上传记录失败,Code:{( int ) recordData.Code},原因:{recordData.RawText}");
  607. /////记录至数据库
  608. //Rt_AngelNetRecordDto recordDto = new Rt_AngelNetRecordDto()
  609. //{
  610. // DevcieId = DataPathcs.GetConnectionStringsConfig("DeviceID"),
  611. // EquipmentType = 4,
  612. // UserId = UserName,
  613. // descriptions = new List<Description>() {
  614. // new Description(){ Key="BoardId",KeyValue=RfidId },
  615. // new Description(){ Key="Code",KeyValue=recordData.Code.ToString() },
  616. // new Description(){ Key="RawText",KeyValue=recordData.RawText }
  617. // }
  618. //};
  619. //var recorddata = alignServer.InsertProductionRecord(recordDto);
  620. return $"{recordData.RawText}";
  621. }
  622. }
  623. catch ( Exception ex )
  624. {
  625. LogHelper.Error($"网板ID:{RfidId}上传记录异常,原因{ex.Message}");
  626. return ex.ToString();
  627. }
  628. }
  629. /// <summary>
  630. /// 小票打印
  631. /// </summary>
  632. /// <param name="printinfo"></param>
  633. /// <param name="Position"></param>
  634. public void PrintInfo(ProcessDataModel printinfo, string Position)
  635. {
  636. try
  637. {
  638. var pmTitle = new PrintModel
  639. {
  640. FontFamily = "宋体",
  641. FontSize = 15,
  642. IsBold = true,
  643. Text = new StringReader("\n" + "<<<<后处理收料信息>>>>") //首行需要空行,某些打印机首行不为空时会出现“首行乱码问题”
  644. };
  645. var count = 0;
  646. if ( printinfo.SolidifyStation != 0 )
  647. {
  648. count = printinfo.SolidifyStation % 2 == 1 ? 1 : 2;
  649. }
  650. var printContent = new StringBuilder();
  651. printContent.Append("<<<----------------------------->>>" + "\n");
  652. printContent.Append($"出料窗口:{CurentApplicationSettings.DeviceId}" + $",{Position}传送带,第{count}板" + "\n");
  653. printContent.Append($"网板编号:{printinfo.BoardId}" + "\n");
  654. printContent.Append("出票时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\n");
  655. printContent.Append("<<<----------------------------->>>" + "\n");
  656. printContent.Append(" " + "\n");
  657. var batchs = new PrintModel
  658. {
  659. FontFamily = "宋体",
  660. FontSize = 12,
  661. IsBold = true,
  662. Text = new StringReader(printContent.ToString())
  663. };
  664. var sb = new StringBuilder();
  665. if ( !string.IsNullOrEmpty(printinfo.Tip) )
  666. {
  667. sb.Append($"记录上传异常:{printinfo.Tip}" + "\n");
  668. }
  669. sb.Append($"3D打印设备:{printinfo.PrintDeviceId}" + "\n");
  670. sb.Append($"批次:{printinfo.ModelsInfo}" + "\n");
  671. sb.Append($"膜片规格:{printinfo.MaterialType}" + "\n");
  672. sb.Append($"类型:{printinfo.PrintTagProduct}" + "\n");
  673. sb.Append($"品牌:{printinfo.Brand}" + "\n");
  674. sb.Append($"是否Kid:{( printinfo.IsKid == true ? "是" : "否" )}" + "\n");
  675. sb.Append($"是否海外:{( printinfo.IsOverSea == true ? "是" : "否" )}" + "\n");
  676. sb.Append($"大小载具:{printinfo.IsLarge}" + "\n");
  677. sb.Append($"数量:{printinfo.Count.ToString()}" + "\n");
  678. var pmContent2 = new PrintModel
  679. {
  680. FontFamily = "宋体",
  681. FontSize = 10,
  682. IsBold = false,
  683. Text = new StringReader(sb.ToString().Trim())
  684. };
  685. PrintModel[] pms = { pmTitle, batchs, pmContent2 };
  686. LogHelper.Info($"打印内容{printContent}" + "\n" + sb + "\n" + "<<<------------------------------->>>");
  687. TicketPrinterHelper.Print(pms, CurentApplicationSettings.PrinterName);
  688. }
  689. catch ( Exception ex )
  690. {
  691. LogHelper.Error("打印异常,原因:" + ex.ToString());
  692. }
  693. }
  694. }
  695. }