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