1
dengjunjie
2025-03-11 c455612b03e6ecac994884dde5b5f4bc4909c181
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_BasicService/PalletCodeInfoService.cs
@@ -1,10 +1,14 @@
using BarcodeStandard;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Information;
using SkiaSharp;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core;
@@ -42,6 +46,8 @@
                    Width = Width,
                    Height = Height,
                    Size = Size,
                    Qty = 1,
                    PrintFrequency = 2,
                };
                BaseDal.AddData(palletCodeInfo);
                return WebResponseContent.Instance.OK();
@@ -51,7 +57,73 @@
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        /// <summary>
        /// æ‰“印条码
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        public WebResponseContent PrintBarcodeLib(List<int> keys)
        {
            try
            {
                Dt_PalletCodeInfo palletCodeInfo = BaseDal.QueryFirst(x => keys.Contains(x.Id));
                if (palletCodeInfo == null) throw new Exception("信息有误");
                #region ç”Ÿæˆæ¡ç 
                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.Code128;
                barcode.Width = palletCodeInfo.Width;
                barcode.Height = palletCodeInfo.Height;
                #endregion
                for (int i = 1; i <= palletCodeInfo.Qty; i++)
                {
                    #region ç”Ÿæˆæ¡å½¢ç å›¾åƒ
                    var n = DateTime.Now.ToString("yy");
                    var Barcode = n + palletCodeInfo.Code.ToString("000000");
                    //var Barcode = palletCodeInfo.PalletCode + palletCodeInfo.Code.ToString("00000000");
                    palletCodeInfo.Code++;
                    SKImage bitmap = barcode.Encode(Barcode);
                    #endregion
                    for (int j = 1; j <= palletCodeInfo.PrintFrequency; j++)
                    {
                    }
                }
                return WebResponseContent.Instance.OK("打印成功");
            }
            catch (Exception ex)
            {
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        public string newBarcodeLib(int key)
        {
            Dt_PalletCodeInfo palletCodeInfo = BaseDal.QueryFirst(x => key == x.Id);
            Barcode barcode = new Barcode();//创建条形码对象
            barcode.IncludeLabel = true;//确保包括标签
            barcode.Alignment = AlignmentPositions.Center;//条形码对齐方式
            barcode.LabelFont = new SKFont
            {
                Typeface = SKTypeface.FromFamilyName("Arial", SKFontStyle.Bold),//字体样式
                Size = palletCodeInfo.Size,// æ ‡ç­¾å­—体
            };
            barcode.EncodedType = BarcodeStandard.Type.Code128;
            barcode.Width = palletCodeInfo.Width;
            barcode.Height = palletCodeInfo.Height;
            var Barcode = DateTime.Now.ToString("yy") + palletCodeInfo.Code.ToString("000000");
            palletCodeInfo.Code++;
            BaseDal.UpdateData(palletCodeInfo);
            SKImage bitmap = barcode.Encode(Barcode);
            var a = barcode.EncodedImageBytes;
            return Convert.ToBase64String(a, 0, (int)a.Length);
        }
        public string newBarcodeLib(palletCodeInfoDTO palletCodeInfo)
        {
            #region ç”Ÿæˆæ¡å½¢ç 
@@ -75,9 +147,9 @@
            //设置条形码尺寸
            barcode.Width = palletCodeInfo.Width;
            barcode.Height = palletCodeInfo.Height;
            var Barcode = DateTime.Now.ToString("yy") + palletCodeInfo.Code.ToString("000000");
            //生成条形码图像
            SKImage bitmap = barcode.Encode(palletCodeInfo.PalletCode);
            SKImage bitmap = barcode.Encode(Barcode);
            var a = barcode.EncodedImageBytes;
            var b = Convert.ToBase64String(a, 0, (int)a.Length);
            //保存条形码图像到文件(可选)