wankeda
2025-03-13 a6a33f6916afbf1fc629baecb772939cda2ee981
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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);
        }
    }
}