1
huangxiaoqiang
10 小时以前 a296223898d61a9838bbd35ed75c87575e308a36
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
using FastReport;
using FastReport.Barcode;
using FastReport.Table;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
 
namespace Print.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class PrintController : Controller
    {
        const string PrintName = "Deli DL-888B(NEW)";
        [HttpGet, HttpPost, Route("PrintInboundOrder"), AllowAnonymous]
        public object PrintInboundOrder([FromBody] List<InboundOrder> inbounds)
        {
            try
            {
                foreach (var inbound in inbounds)
                {
                    string ReportPathmater = System.IO.Directory.GetCurrentDirectory();
                    string MFile = string.Empty;
                    MFile = ReportPathmater + "\\frx\\InboundOrder.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 = PrintName;
                    BarcodeObject OrderNoObj = report.FindObject("OrderNo") as BarcodeObject;
                    if (OrderNoObj != null)
                    {
                        OrderNoObj.Text = inbound.OrderNo;
                    }
                    TableCell UpperOrderNoObj = report.FindObject("UpperOrderNo") as TableCell;
                    if (UpperOrderNoObj != null)
                    {
                        UpperOrderNoObj.Text = inbound.UpperOrderNo;
                    }
                    TableCell WarehouseNameObj = report.FindObject("WarehouseName") as TableCell;
                    if (WarehouseNameObj != null)
                    {
                        WarehouseNameObj.Text = inbound.WarehouseName;
                    }
                    TableCell MaterialNoObj = report.FindObject("MaterialNo") as TableCell;
                    if (MaterialNoObj != null)
                    {
                        MaterialNoObj.Text = inbound.MaterialNo;
                    }
                    TableCell MaterialNameObj = report.FindObject("MaterialName") as TableCell;
                    if (MaterialNameObj != null)
                    {
                        MaterialNameObj.Text = inbound.MaterialName;
                    }
                    TableCell SpecsObj = report.FindObject("Specs") as TableCell;
                    if (SpecsObj != null)
                    {
                        SpecsObj.Text = inbound.Specs;
                    }
                    TableCell UnitObj = report.FindObject("Unit") as TableCell;
                    if (UnitObj != null)
                    {
                        UnitObj.Text = inbound.Unit;
                    }
                    TableCell QuantityObj = report.FindObject("Quantity") as TableCell;
                    if (QuantityObj != null)
                    {
                        QuantityObj.Text = inbound.Quantity.ToString();
                    }
                    TableCell ProductDrawingNumberObj = report.FindObject("ProductDrawingNumber") as TableCell;
                    if (ProductDrawingNumberObj != null)
                    {
                        ProductDrawingNumberObj.Text = inbound.ProductDrawingNumber;
                    }
                    TableCell DatetimeObj = report.FindObject("Datetime") as TableCell;
                    if (DatetimeObj != null)
                    {
                        DatetimeObj.Text = inbound.Datetime;
                    }
                    TableCell WeightObj = report.FindObject("Weight") as TableCell;
                    if (WeightObj != null)
                    {
                        WeightObj.Text = inbound.Weight.ToString();
                    }
                    report.Print();
                    report.Dispose();
                }
                return new { Code = 200, Status = true , Message = "打印成功" };
            }
            catch (Exception ex)
            {
                return new { Code = 400, Status = false, Message = "打印失败,请查看是否连接打印机" };
            }
        }
 
        [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 = PrintName;
                    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 = "打印失败,请查看是否连接打印机" };
            }
        }
 
 
        public class InboundOrder
        {
            public string OrderNo { get; set; }
            public string UpperOrderNo { get; set; }
            public string WarehouseName { get; set; }
            public string MaterialNo { get; set; }
            public string MaterialName { get; set; }
            public string Specs { get; set; }
            public string Unit { get; set; }
            public decimal Quantity { get; set; }
            public string ProductDrawingNumber { get; set; }
            public string Datetime { get; set; }
            public decimal Weight { get; set; }
        }
    }
}