Management.cs 40 KB

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