Management.cs 40 KB

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