Management.cs 30 KB

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