using System;
|
using System.Collections.Generic;
|
using System.Drawing;
|
using System.Drawing.Printing;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using FastReport;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Information;
|
//using TSCLIB;
|
|
namespace WIDESEA_Tasks
|
{
|
public partial class AGVjob
|
{
|
public static string ReportPath = System.IO.Directory.GetCurrentDirectory();
|
//public void Printer()
|
// {
|
// try
|
// {
|
// //PrintDocument pd = new PrintDocument();
|
// ////string name = Txt_barcode1.Text;
|
// ////if (name == "")
|
// ////{
|
// //// MessageBox.Show("请输入打印数据", "提示", MessageBoxButtons.OKCancel);
|
// //// return;
|
// ////}
|
// //List<string> printData = GetInputTxtData();
|
|
// //if (printData.Count == 0)
|
// //{
|
// // MessageBox.Show("请输入打印数据", "提示", MessageBoxButtons.OK);
|
// // return;
|
// //}
|
|
// //if (isInputError)
|
// //{
|
// // MessageBox.Show("输入数据有误,请先检查后再打印", "提示", MessageBoxButtons.OK);
|
// // return;
|
// //}
|
|
// //string MFile = ReportPath + "\\FRX\\wl.frx";//FastReport设计后的文件保存的路径。
|
// //if (!File.Exists(MFile))
|
// //{
|
// // MessageBox.Show("未找到托盘条码打印样式文件!");
|
// // return;
|
// //}
|
|
// //Report report = new Report();
|
// //report.Load(MFile);
|
// //report.PrintSettings.ShowDialog = false;
|
// //PrinterSettings oitem = new PrinterSettings();
|
// //if (report.ShowPrintDialog(out oitem) && oitem.Copies > 0)
|
// //{
|
// // foreach (string data in printData)
|
// // {
|
// // report.PrintSettings.ShowDialog = false;
|
// // report.SetParameterValue("Name", data);//给参数赋值(条码)
|
// // //report.SetParameterValue("No", "456");
|
// // //report.SetParameterValue("Qty", "7");
|
// // //report.SetParameterValue("Supplier", "8");
|
// // report.SetParameterValue("Barcode", data);
|
// // report.Print();
|
// // }
|
// //}
|
// //else
|
// //{
|
// // MessageBox.Show("取消打印");
|
// //}
|
// //report.Dispose();
|
|
// #region 原打印逻辑
|
// string MFile = ReportPath + "\\FRX\\wl.frx";//FastReport设计后的文件保存的路径。
|
// if (!File.Exists(MFile))
|
// {
|
// throw new Exception("未找到托盘条码打印样式文件!!!");
|
// }
|
// Report report = new Report();
|
// report.Load(MFile);
|
// report.PrintSettings.ShowDialog = false;
|
// System.Drawing.Printing.PrinterSettings oitem = new System.Drawing.Printing.PrinterSettings();
|
|
// if (report.ShowPrintDialog(out oitem) && oitem.Copies > 0)
|
// {
|
// report.PrintSettings.ShowDialog = false;
|
// report.SetParameterValue("Name", "name");//给参数赋值(条码)
|
// //report.SetParameterValue("No", "456");
|
// //report.SetParameterValue("Qty", "7");
|
// report.SetParameterValue("Supplier", "8");
|
// report.SetParameterValue("Barcode", "name");
|
// report.Print();
|
// }
|
// report.Dispose();
|
// #endregion
|
|
// }
|
// catch (Exception ex)
|
// {
|
// //MessageBox.Show($"打印异常:{ex.Message}");
|
// }
|
//}
|
|
|
|
|
public void Main()
|
{
|
var agvtask = _taskService.GetTasks();
|
// 创建TSC打印机实例
|
//TSCPrinter printer = new TSCPrinter();
|
|
//// 连接到打印机
|
//printer.Connect("TSC Printer", "LPT1:", 9600);
|
|
//// 初始化打印机
|
//printer.InitializePrinter();
|
|
//// 创建一个Bitmap图像
|
//Bitmap bitmap = new Bitmap(200, 100);
|
//using (Graphics g = Graphics.FromImage(bitmap))
|
//{
|
// // 绘制图像
|
// g.FillRectangle(Brushes.White, 0, 0, 200, 100);
|
// g.DrawString("Hello, TSC Printer!", new Font("Arial", 12), Brushes.Black, 20, 20);
|
//}
|
|
//// 发送图像到打印机
|
//printer.SendImage(bitmap, 10, 10);
|
|
//// 添加ZPL指令打印图像
|
//printer.SendCommand("^XA^FO10,10^GFA,^FS");
|
|
//// 断开与打印机的连接
|
//printer.Disconnect();
|
|
PrintDocument printDocument = new PrintDocument();
|
printDocument.PrintPage += new PrintPageEventHandler(PrintPage);
|
printDocument.Print();
|
}
|
|
private void PrintPage(object sender, PrintPageEventArgs e)
|
{
|
var agvtask = _taskService.GetTasks();
|
string textToPrint = "放货位:" + agvtask.SourceAddress + Environment.NewLine + "物料类型:" + agvtask.Materialtype + Environment.NewLine + "任务创建时间:" + agvtask.CreateDate;
|
Font printFont = new Font("Arial", 12);
|
e.Graphics.DrawString(textToPrint, printFont, Brushes.Black, 10, 10);
|
}
|
}
|
}
|