//检索结果集里有多少个DMP文件 public void DMPFile(String FileNameBase) { DMPs = new List <DMPFile>(); String FileContent = ""; foreach (string str in DMP) { //如果结果集有DMP文件,就把文件保存起来 if (OrderResult.Contains(str)) { //发送指令到打印机获取到DMP文件文本 string teststr = "! U1 do \"file.type\" \"" + str + "\" "; FileContent = frmMainmF.SendRawDataToPrinter("! U1 do \"file.type\" \"" + str + "\" ", SN); //FileContent = server.SendRawData(SN, "! U1 do \"file.type\" \"" + str + "\" ", 1500); //string labelID = DMPContentEstimate(FileContent); //改用陆逊梯卡的模板 string labelID = DMPContentEstimate2(FileContent); DMPs.Add(new DMPFile { FileName = str, LaBelID = labelID, FileSize = FileContent.Length }); if (FileContent != "") { //这里需要判断文件是否存在,有替换或取消的选项 StreamWriter streamWrite = new StreamWriter(FileNameBase + "\\" + str); streamWrite.Write(FileContent); //写入数据 streamWrite.Close(); //关闭文件 } } else { break; } } }
private void RealTime(object sender, EventArgs e) { if (TextHighPrinter.linkOSPrinter != null) { String command = "{}{\"media\":null,\"head\":null,\"power\":null,\"device\":null}"; String command2 = "{}{\"media.status\":null,\"head.latch\":null,\"power.percent_full\":null,\"device.product_name\":null,\"odometer.media_marker_count1\":null}"; String command3 = "{}{\"media.status\":null,\"head.latch\":null,\"power.percent_full\":null," + "\"device.product_name\":null,\"odometer.media_marker_count1\":null,\"print.tone\":null," + "\"media.speed\":null,\"media.printmode\":null}"; String message = ""; String[] str; ArrayList array; linkOSPrinter2 = TextHighPrinter.linkOSPrinter; foreach (var item in linkOSPrinter2) { message = mainWindow.SendRawDataToPrinter(command3, item.SN); //message有可能是:Device:XXZKJ181100121 is not online.需不需要做判断 //将Json数据保存到指定打印机的Json文件中 string file = $"{FileTools.LinkOSPrintersJsonPath}\\{item.SN}.json"; FileTools.WriteNewFile(file, message); //将接收到的信息发送给JSON解析出想要的信息 str = LinkOSRealTime.SetJsonMessage(message); //返回一个数组 //array = LinkOSRealTime.SetJsonMessageForList(message); //返回一个列表 if (str != null) { item.WareStatus = str[0]; item.HeadStatus = str[1]; item.PowerFull = str[2]; item.PrinterType = str[3]; item.PrintOdometer = str[4]; } /*if (array != null) * { * item.WareStatus = array[0]; * foreach (var msg in array) * { * item.WareStatus = msg.; * } * }*/ } lvMonitor.ItemsSource = linkOSPrinter2; } else { //linkOSPrinter2.Clear(); //lvMonitor.Items.Clear(); } }
private void btnGetPrinterFile_Click(object sender, RoutedEventArgs e) { try { //frmMainmF = new WebSocketConsole.MainWindow(); if (txtSN.Text != "") { SN = txtSN.Text; //这里需要遍历一次LinkOSPrinters里的SN属性,是否存在这个SN码 OrderResult = frmMainmF.SendRawDataToPrinter("^XA^HWE:^XZ", txtSN.Text); txtPrinterFile.Text = OrderResult; } else { MessageBox.Show("SN为空,请输入SN码!", this.Title, MessageBoxButton.OK); } } catch (Exception ex) { MessageBox.Show(ex.Message, this.Title, MessageBoxButton.OK); } }