Management.cs 37 KB

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