public string print(string printListJson) { string error = "NULL"; if (CheckTools.isNull(printListJson)) { return(error); } PrinterList printerList = JsonConvert.DeserializeObject <PrinterList>(printListJson); if (printerList == null) { return(error); } if (printerList.command == null) { printerList.command = "print"; } if (string.Equals("print", printerList.command, StringComparison.CurrentCultureIgnoreCase)) { print(true, printerList); error = printerList.errorMsg; } else { error = printListJson; } //StringBuilder sb = new StringBuilder(printerList.listId == null ? "" : printerList.listId.ToString()).Append("ACK".Equals(error) ? "打印成功!" : error); //error = sb.ToString(); //sb.Clear(); return(error); }
private void GetPrinterFromDb() { PrinterList.Clear(); int i = 0; var items = PrinterList.Items; try { using (var con = new MySqlConnection(cs)) { con.Open(); var query = "SELECT PrinterName FROM printers"; using (var cmd = new MySqlCommand(query, con)) { using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { items.Add(reader.GetString("PrinterName")); PrinterList.Items[i].ImageIndex = 0; i++; } } } } } catch (MySqlException) { } }
private void UpdatePrintResult(PrinterList printer) { Dictionary <string, string> parameters = new Dictionary <string, string>(3); parameters.Add("listId", printer.listId.ToString()); parameters.Add("printResult", printer.printResult.ToString()); parameters.Add("errorMsg", printer.errorMsg); string result = null; result = HttpRequestClientUtil.doPost(StaticUtil.PRINT_ADDRESS + "/printer/updatePrinterListResult", StaticUtil.DEFAULT_CHARSET, 60000, null, parameters, StaticUtil.USER_COOKIE_BEAN.Cookies); if (null == result) { MessageBoxEx.Show(this, "请求超时,请检查网络!", "提示", MessageBoxButtons.OK); } else { try { Result <int?> data = JsonConvert.DeserializeObject <Result <int?> >(result); if (data.success && data.bizErrCode == 20000 && data.data > 0) { } else { this.txt_print_log.AppendText("远程HTTP打印服务异常提示:" + data.defaultRequestFailShow() + "\r\n"); } } catch (Exception e) { Console.WriteLine("MainForm.UpdatePrintResult序列化异常:" + e.Message); } } }
public override async void OnNavigatedTo(INavigationParameters parameters) { try { if (PrinterList == null) { PrinterList = await _restClient.GetPrinterList(); } if (Printer == null) { Printer = PrinterList.FirstOrDefault(p => Settings.Printer.Equals(p.PrinterName)); if (Printer == null) { Settings.Printer = string.Empty; } } if (LabelTemplateList == null) { LabelTemplateList = await _restClient.GetLabelTemplateList(); } if (parameters.ContainsKey("inventoryList")) { _inventoryList = (List <InventoryThumbnail>)parameters["inventoryList"]; } } catch (Exception ex) { await _pageDialogService.DisplayAlertAsync("Error", ex.Message, "OK"); } }
private static void OnResponse(IAsyncResult ar) { RequestState state = ar.AsyncState as RequestState; try { HttpWebRequest request = state.Request; HttpWebResponse response = request.EndGetResponse(ar) as HttpWebResponse; using (StreamReader read = new StreamReader(response.GetResponseStream(), Encoding.UTF8)) { string html = read.ReadToEnd(); state.Host.Html = html; GetPrinterType(state); GetPrinterStatus(state); Regex replaceSpace = new Regex(@"[\s]+", RegexOptions.IgnoreCase); // 去掉连续空格 string pstatus, tstatus; pstatus = state.Printer.PrinterStatus.Replace("<br>", "").Replace("\n", "").Replace("</pre>", "").Trim(); tstatus = state.Printer.TonerStatus.Replace("<br>", "").Replace("\n", "").Replace("*", "").Trim(); pstatus = replaceSpace.Replace(pstatus, " "); tstatus = replaceSpace.Replace(tstatus, " "); state.Printer.PrinterStatus = pstatus; state.Printer.TonerStatus = tstatus; if (pstatus.IndexOf("StartIndex") == -1) { if (state.IsIndexQuery) { indexCount++; } else { count++; PrinterList.Add(state.Printer); Console.WriteLine(count.ToString() + "/" + storeCount.ToString() + " " + state.Printer.StoreNo + ": " + state.Printer.PrinterStatus + " " + state.Printer.TonerStatus); } } } response.Close(); } catch (System.Exception ex) { state.Printer.PrinterStatus = ex.Message; state.Printer.TonerStatus = ex.Message; state.Printer.PrinterNetwork = "Down"; state.Printer.Date = DateTime.Now.ToString(); if (state.IsIndexQuery) { indexCount++; } else { count++; PrinterList.Add(state.Printer); Console.WriteLine(count.ToString() + "/" + storeCount.ToString() + " " + state.Printer.StoreNo + ": " + ex.Message.ToString()); } } }
private void DiscoveryHandler_OnFoundPrinter(object sender, IDiscoveredPrinter discoveredPrinter) { System.Diagnostics.Debug.WriteLine("Found Printer:" + discoveredPrinter.ToString()); Device.BeginInvokeOnMainThread(() => { if (!PrinterList.Contains(discoveredPrinter)) { PrinterList.Add(discoveredPrinter); } }); }
public SettingToPrintViewModel(IPrintPDF pDFPrinter, IPrintExcel excelPrinter) { PDFPrinter = pDFPrinter; ExcelPrinter = excelPrinter; //PDFFilesToPrint = pDFFilesToPrint; foreach (var item in PrinterSettings.InstalledPrinters) { PrinterList.Add(item.ToString()); } PropertyCommand = new RelayCommand(PropertySet); OKCommand = new RelayCommand(OK); CancelCommand = new RelayCommand(Cancel); OptionCommand = new RelayCommand(Option); }
private void PopulatePrinterList() { try { PrinterSettings ps = new PrinterSettings(); foreach (string item in PrinterSettings.InstalledPrinters) { PrinterList.Add(item); } } catch (Exception ex) { this.messageBoxService.ShowError(this.GetType().FullName + System.Reflection.MethodBase.GetCurrentMethod().Name + ": " + ex.Message); } }
private void RemovePrinter_Click(object sender, EventArgs e) { try { MySqlConnection con = new MySqlConnection(cs); MySqlCommand cmd = con.CreateCommand(); cmd.CommandText = "DELETE FROM printers where PrinterName='" + PrinterList.SelectedItems[0].Text + "' "; con.Open(); cmd.ExecuteNonQuery(); con.Close(); PrinterList.Clear(); GetPrinterFromDb(); } catch (MySqlException) { } catch (Exception) { } }
//Button Action testseite drucken public IActionResult TestPrinter(string PrinterName) { if (ModelState.IsValid) { string folderPath = @"C:\Users\BenOmran\Desktop\savepdf"; PrinterList = GetAllItems().ToList(); var printer = PrinterList.Single(d => d.DeviceName == PrinterName); if (printer.DeviceType == "Printer" && printer.DeviceSubtype == "A4") { FileStream PdfA4 = new FileStream("Test-A4.pdf", FileMode.Open, FileAccess.Read); PdfLoadedDocument loadedDocumentA4 = new PdfLoadedDocument(PdfA4); MemoryStream stream = new MemoryStream(); loadedDocumentA4.Save(stream); PdfViewer pdfViewer = new PdfViewer(); var myUniqueFileName = $@"Test-A4_{Guid.NewGuid()}.pdf"; using (var file = new FileStream(Path.Combine(folderPath, myUniqueFileName), FileMode.Create, FileAccess.Write)) { stream.WriteTo(file); pdfViewer.BindPdf(PdfA4); pdfViewer.PrintDocument(); AddQ(PrinterName, file.Name); } } else if (printer.DeviceType == "Printer" && printer.DeviceSubtype == "Label") { FileStream PdfLabel = new FileStream("Test-Label-3,9x7,9-inch.pdf", FileMode.Open, FileAccess.Read); PdfLoadedDocument loadedDocumentLabel = new PdfLoadedDocument(PdfLabel); MemoryStream stream = new MemoryStream(); loadedDocumentLabel.Save(stream); PdfViewer pdfViewer = new PdfViewer(); var myUniqueFileName = $@"Test-Label-3,9x7,9-inch_{Guid.NewGuid()}.pdf"; using (var file = new FileStream(Path.Combine(folderPath, myUniqueFileName), FileMode.Create, FileAccess.Write)) { stream.WriteTo(file); pdfViewer.BindPdf(PdfLabel); pdfViewer.PrintDocument(); AddQ(PrinterName, file.Name); } } } return(RedirectToAction("Index")); }
private bool CanEditPrinter(object param) { if (param == null) { return(false); } if (PrinterList == null || PrinterList.Count <= 0) { return(false); } if (PrinterList.Where(c => c.Id == ((Printer)param).Id).SingleOrDefault() == null) { return(false); } return(true); }
public PrinterList print(bool isPrint, PrinterList printerList) { string error = null; if (printerList == null) { error = "无可用打印数据"; printerList.printResult = 2; printerList.errorMsg = error; return(printerList); } if (CheckTools.isNull(printerList.templateFileName)) { error = "打印模板名称不允许为空"; printerList.printResult = 2; printerList.errorMsg = error; return(printerList); } IDictionary <string, string> fixedField = null; if (!CheckTools.isNull(printerList.printerJson)) { try { fixedField = JsonConvert.DeserializeObject <IDictionary <string, string> >(printerList.printerJson); } catch (Exception e) { //Console.WriteLine("CallServiceThread序列化异常:" + e.Message); error = e.Message; } } IDictionary <string, DataTable> listField = null; if (!CheckTools.isNull(printerList.printerListJson)) { try { listField = JsonConvert.DeserializeObject <IDictionary <string, DataTable> >(printerList.printerListJson); } catch (Exception e) { //Console.WriteLine("CallServiceThread序列化异常:" + e.Message); error = e.Message; } } //序列化出错 if (error != null) { printerList.printResult = 2; printerList.errorMsg = error; return(printerList); } if ((fixedField == null || fixedField.Count == 0) && (listField == null || listField.Count == 0)) { error = "打印模板内容参数printerJson或printerListJson不允许同时为空"; printerList.printResult = 2; printerList.errorMsg = error; return(printerList); } string filename; int dot = printerList.templateFileName.IndexOf("."); if (dot == -1) { filename = printerList.templateFileName; printerList.templateFileName += ".xlsx"; } else { filename = printerList.templateFileName.Substring(0, dot); } string exportOutFileName = filename + "_"; if (printerList.listId == null) { exportOutFileName += StaticUtil.ConvertDateTimeToTimestamp(printerList.requestTime); } else { exportOutFileName += printerList.listId; } try { string excelFileName = new ExcelUtil().TemplateExport(printerList.templateFileName, exportOutFileName, fixedField, listField); if (printerList.command == null) { printerList.command = "print"; } if (string.Equals("print", printerList.command, StringComparison.CurrentCultureIgnoreCase)) { StaticUtil.Print(excelFileName); } //打印结果0待打印1打印成功2打印失败 printerList.printResult = 1; printerList.errorMsg = "ACK"; } catch (Exception e) { Console.WriteLine("CallServiceThread.ExcelUtil.TemplateExport异常" + e); error = e.Message; printerList.printResult = 2; printerList.errorMsg = error; } return(printerList); }