using BarcodeStandard;
|
using SkiaSharp;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Drawing.Imaging;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Core;
|
using WIDESEA_Core.BaseServices;
|
using WIDESEA_Core.Helper;
|
using WIDESEA_DTO.Basic;
|
using WIDESEA_IBasicRepository;
|
using WIDESEA_IBasicService;
|
using WIDESEA_Model.Models;
|
|
namespace WIDESEA_BasicService
|
{
|
public class PalletCodeInfoService : ServiceBase<Dt_PalletCodeInfo, IPalletCodeInfoRepository>, IPalletCodeInfoService
|
{
|
private readonly IWarehouseRepository _warehouseRepository;
|
|
public PalletCodeInfoService(IPalletCodeInfoRepository BaseDal, IWarehouseRepository warehouseRepository) : base(BaseDal)
|
{
|
_warehouseRepository = warehouseRepository;
|
}
|
public override WebResponseContent AddData(SaveModel saveModel)
|
{
|
try
|
{
|
string PalletCode = saveModel.MainData["palletCode"].ToString();
|
int Width = saveModel.MainData["width"].ObjToInt();
|
int Height = saveModel.MainData["height"].ObjToInt();
|
int Size = saveModel.MainData["size"].ObjToInt();
|
if (string.IsNullOrEmpty(PalletCode)) throw new Exception("托盘号不能为空");
|
Dt_PalletCodeInfo palletCodeInfo = BaseDal.QueryFirst(x => x.PalletCode == PalletCode);
|
if (palletCodeInfo != null) throw new Exception("托盘号已存在");
|
palletCodeInfo = new Dt_PalletCodeInfo()
|
{
|
PalletCode = PalletCode,
|
Width = Width,
|
Height = Height,
|
Size = Size,
|
};
|
BaseDal.AddData(palletCodeInfo);
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
|
public string newBarcodeLib(palletCodeInfoDTO palletCodeInfo)
|
{
|
#region 生成条形码
|
if (palletCodeInfo == null) throw new Exception("信息有误");
|
Barcode barcode = new Barcode();//创建条形码对象
|
barcode.IncludeLabel = true;//确保包括标签
|
barcode.Alignment = AlignmentPositions.Center;//条形码对齐方式
|
barcode.LabelFont = new SKFont
|
{
|
Typeface = SKTypeface.FromFamilyName("Arial", SKFontStyle.Normal),//字体样式
|
Size = palletCodeInfo.Size,// 标签字体
|
};
|
|
//设置条形码类型
|
//barcode.EncodedType = BarcodeStandard.Type.UpcA;//11-12纯数字
|
barcode.EncodedType = BarcodeStandard.Type.Code128;// 数据应该包括数字和字母
|
|
//设置条形码数据
|
//barcode.RawData = "AA12345";
|
|
//设置条形码尺寸
|
barcode.Width = palletCodeInfo.Width;
|
barcode.Height = palletCodeInfo.Height;
|
|
//生成条形码图像
|
SKImage bitmap = barcode.Encode(palletCodeInfo.PalletCode);
|
var a = barcode.EncodedImageBytes;
|
var b = Convert.ToBase64String(a, 0, (int)a.Length);
|
//保存条形码图像到文件(可选)
|
//barcode.SaveImage("C://Users//dell//Desktop//1.控制打印机/barcode.png", SaveTypes.Png);
|
|
// 打印条形码图像(需要有打印机,并且配置好打印机)
|
//barcode.Print();
|
|
// 清理资源
|
//barcode.Dispose();
|
#endregion
|
return b;
|
}
|
}
|
}
|