载具条码打印

This commit is contained in:
2024-01-10 13:40:40 +08:00
parent d25ba04ee5
commit 3504aefa0e
2 changed files with 148 additions and 1 deletions

View File

@@ -346,6 +346,138 @@ namespace Tnb.WarehouseMgr
}
/// <summary>
/// 载具条码打印
/// </summary>
/// <param name="barCodes">条码</param>
/// <param name="copies">打印份数</param>
/// <returns></returns>
[NonAction]
protected void CarryPrint(List<string> barCodes, int copies, string ip)
{
TaskCompletionSource tcs = new();
// open port.
try
{
int nLen, ret, sw;
byte[] pbuf = new byte[128];
string strmsg;
IntPtr ver;
System.Text.Encoding encAscII = System.Text.Encoding.ASCII;
System.Text.Encoding encUnicode = System.Text.Encoding.Unicode;
// dll version.
ver = PPLBUtility.B_Get_DLL_Version(0);
// search port.
nLen = PPLBUtility.B_GetUSBBufferLen() + 1;
strmsg = "DLL ";
strmsg += Marshal.PtrToStringAnsi(ver);
strmsg += "\r\n";
if (nLen > 1)
{
byte[] buf1, buf2;
int len1 = 128, len2 = 128;
buf1 = new byte[len1];
buf2 = new byte[len2];
_ = PPLBUtility.B_EnumUSB(pbuf);
_ = PPLBUtility.B_GetUSBDeviceInfo(1, buf1, out len1, buf2, out len2);
sw = 1;
if (1 == sw)
{
ret = PPLBUtility.B_CreatePrn(12, encAscII.GetString(buf2, 0, len2));// open usb.
}
else
{
ret = PPLBUtility.B_CreateUSBPort(1);// must call B_GetUSBBufferLen() function fisrt.
}
if (0 != ret)
{
strmsg += "Open USB fail!";
}
else
{
strmsg += "Open USB:\r\nDevice name: ";
strmsg += encAscII.GetString(buf1, 0, len1);
strmsg += "\r\nDevice path: ";
strmsg += encAscII.GetString(buf2, 0, len2);
//sw = 2;
if (2 == sw)
{
//Immediate Error Report.
_ = PPLBUtility.B_WriteData(1, encAscII.GetBytes("^ee\r\n"), 5);//^ee
ret = PPLBUtility.B_ReadData(pbuf, 4, 1000);
}
}
}
else
{
ret = PPLBUtility.B_CreatePrn(13, ip);
}
/* else
{
_ = System.IO.Directory.CreateDirectory(PPLBUtility.szSavePath);
ret = PPLBUtility.B_CreatePrn(0, PPLBUtility.szSaveFile);// open file.
strmsg += "Open ";
strmsg += PPLBUtility.szSaveFile;
if (0 != ret)
{
strmsg += " file fail!";
}
else
{
strmsg += " file succeed!";
}
}*/
if (0 != ret)
{
return;
}
// sample setting.
_ = PPLBUtility.B_Set_Originpoint(0, 0);
_ = PPLBUtility.B_Select_Option(2);
_ = PPLBUtility.B_Set_Darkness(8);
_ = PPLBUtility.B_Del_Pcx("*");// delete all picture.
//PPLBUtility.B_Set_LabelForSmartPrint(254 * 3, 30);//label information: length= 3 * 25.4 mm, gap= 3 mm. 254 * 3, 30
_ = PPLBUtility.B_Set_Labwidth(80 * 8);
//var labelWidth = 640; //254 * 3; // 标签宽度
//var barcodeWidth = 320; // 条码宽度
//var barcodeX = (labelWidth - barcodeWidth) / 2;
//B_Prn_Barcode(barcodeX, 100, 0, "QRcode", 1, 0, 2, 2, "YourBarcodeData"); 8
foreach (string code in barCodes)
{
for (int i = 0; i < copies; i++)
{
// _ = PPLBUtility.B_Prn_Text(50, 90, 0, 2, 2, 2, 'N', code);
// _ = PPLBUtility.B_Prn_Barcode(50, 270, 0, "1", 3, 5, 70, 'N', code);
//_ = PPLBUtility.B_Prn_Text(50, 100, 0, 2, 2, 2, 'N', code);
//_ = PPLBUtility.B_Prn_Barcode(50, 150, 0, "1", 3, 5, 100, 'N', code);
_ = PPLBUtility.B_Prn_Text(50, 100, 0, 2, 2, 2, 'N', code);
_ = PPLBUtility.B_Prn_Barcode(50, 150, 0, "1", 3, 5, 90, 'N', code);
//_ = PPLBUtility.B_Prn_Text(50, 305, 0, 2, 2, 2, 'N', code);
_ = PPLBUtility.B_Print_Out(1);
}
}
}
catch (Exception ex)
{
tcs.SetException(ex);
throw ex;
Logger.Error("条码打印时出现错误", ex);
}
finally
{
// close port.
PPLBUtility.B_ClosePrn();
}
}
#region
/// <summary>
/// 打印
@@ -393,7 +525,7 @@ namespace Tnb.WarehouseMgr
// tcs.SetResult(printerList);
// return tcs.Task;
//}
#endregion
#endregion
/// <summary>
/// Api响应结果

View File

@@ -5,9 +5,11 @@ using JNPF.VisualDev;
using JNPF.VisualDev.Entitys.Dto.VisualDev;
using JNPF.VisualDev.Interfaces;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Tnb.BasicData.Entities;
using Tnb.WarehouseMgr.Entities;
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
using Tnb.WarehouseMgr.Entities.Enums;
using Tnb.WarehouseMgr.Interfaces;
@@ -111,6 +113,19 @@ namespace Tnb.WarehouseMgr
}
return row > 0;
}
/// <summary>
/// 载具条码打印
/// </summary>
/// <param name="input"></param>
/// <exception cref="ArgumentNullException"></exception>
[HttpPost]
public void CarryBarCodePrint(CarryBarCodeInput input)
{
if (input == null || input.barCodes.Count < 1) throw new ArgumentNullException(nameof(input));
var ip = _db.Queryable<BasFactoryConfig>().Where(p => p.key == "carrybarcodeprinterip").FirstAsync().Result.value;
base.CarryPrint(input.barCodes, input.copies, ip);
}
}
}