1
wankeda
2026-01-27 a474060ae47fc4c807120b2a6178e8d8f84c0863
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
using FastReport;
using FastReport.Barcode;
using FastReport.Table;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using System.Text.Json;
using System.Text.Json.Serialization;
 
namespace Print.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class PrintController : Controller
    {
        //const string PrintName = @"\\192.168.99.3\Gprinter GP-3120TU";
     
        [HttpGet, HttpPost, Route("PrintPalletCode"), AllowAnonymous]
        public object PrintPalletCode([FromBody] List<string> PalletCodes)
        {
            try
            {
                foreach (var item in PalletCodes)
                {
                    string ReportPathmater = System.IO.Directory.GetCurrentDirectory();
                    string MFile = string.Empty;
                    MFile = ReportPathmater + "\\frx\\PalletCode.frx";
                    Report report = new Report();
                    report.Load(MFile);
                    report.PrintSettings.ShowDialog = false;
                    System.Drawing.Printing.PrinterSettings oitem = new System.Drawing.Printing.PrinterSettings();
                    report.PrintSettings.Printer = oitem.PrinterName;
                    BarcodeObject OrderNoObj = report.FindObject("PalletCode") as BarcodeObject;
                    if (OrderNoObj != null)
                    {
                        OrderNoObj.Text = item;
                    }
                    report.Print();
                    report.Dispose();
                }
                return new { Code = 400, Status = false, Message = "打印成功" };
            }
            catch (Exception ex)
            {
                return new { Code = 400, Status = false, Message = "打印失败,请查看是否连接打印机" };
            }
        }
    }
}