LabelManager.cs 24.0 KB
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OnlineStore.LoadCSVLibrary;
using CodeLibrary;
using OnlineStore.Common;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
using System.Text.RegularExpressions;

namespace OnlineStore.DeviceLibrary
{
    public class LabelManager
    {
        /// <summary>
        /// 计算标签角度
        /// </summary>
        /// <param name="labelParam"></param>
        /// <returns></returns>
        public static int CalcLabelAngle(LabelParam labelParam)
        {
            SolidBrush blue = new SolidBrush(Color.Blue);
            SolidBrush red = new SolidBrush(Color.Red);
            SolidBrush yeelow = new SolidBrush(Color.Yellow);
            SolidBrush blueVio = new SolidBrush(Color.BlueViolet);
            Font font = new Font(FontFamily.GenericSansSerif, 60);
            Pen Greenpen = new Pen(Color.Green, 10);
            int codeAngle = 0;
            int labelAngle = 0;
            string resFile = "";
            int needRound = 0;
            Bitmap srcbitmap;
            if (File.Exists(labelParam.BitmapFilename))
            {
                srcbitmap = new Bitmap(labelParam.BitmapFilename);
            }
            else
            {
                srcbitmap = new Bitmap(labelParam.BitmapWidth, labelParam.BitmapHeight);
            }


            Bitmap bitmap = new Bitmap(srcbitmap.Width, srcbitmap.Height, PixelFormat.Format32bppArgb);
            Graphics g = Graphics.FromImage(bitmap);

            g.DrawImage(srcbitmap, 0, 0);
            int srcbitmap_Width = srcbitmap.Width;
            srcbitmap.Dispose();

            //bitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);//格力
            // bitmap.RotateFlip(RotateFlipType.Rotate180FlipNone);

            Size pointsize = new Size(300, 300);
            Point centerPointInImg = new Point(labelParam.TrayCenterInImg_X, labelParam.TrayCenterInImg_Y);
            g.FillEllipse(red, new Rectangle(centerPointInImg, pointsize));
            CodeInfo codeInfo = labelParam.LabelContent.codeInfos.Find(c => !string.IsNullOrEmpty(labelParam.LabelContent.PN) && c.CodeStr.Contains(labelParam.LabelContent.PN));
            labelAngle = 0;//标签角度
            int widthOffset;
            if (codeInfo != null)
            {
                Point op = new Point(codeInfo.X, codeInfo.Y);
                g.FillEllipse(blue, new Rectangle(op, pointsize));
                codeAngle = (int)getAngle(centerPointInImg, op);
                widthOffset = (int)distance(centerPointInImg, op);
                codeAngle = codeAngle > 0 ? codeAngle : codeAngle + 360;
                labelParam.RelativeAngle = labelParam.RelativeAngle > 0 ? labelParam.RelativeAngle : labelParam.RelativeAngle + 360;
                labelAngle = labelParam.RelativeAngle + codeAngle;

                labelAngle = labelAngle > 0 ? labelAngle : labelAngle + 360;
                var p1 = PointWithAngle(centerPointInImg, labelAngle, widthOffset);
                g.FillEllipse(yeelow, new Rectangle(p1, pointsize));
                labelParam.LabelInImgAngle = labelParam.LabelInImgAngle > 0 ? labelParam.LabelInImgAngle : labelParam.LabelInImgAngle + 360;

                needRound = (labelParam.RelativeAngle - labelParam.LabelInImgAngle) + codeAngle;
                needRound = needRound % 360;
                //needRound = needRound > 360 ? needRound - 360 : needRound;

                if (needRound > 180)
                    needRound = needRound - 360;
                else if (needRound < -180)
                {
                    needRound = needRound + 360;
                }
                var p2 = PointWithAngle(centerPointInImg, labelParam.LabelInImgAngle, widthOffset);
                g.FillEllipse(blueVio, new Rectangle(p2, pointsize));
            }
            else
            {
                LogUtil.error($"贴标未找到料号【{labelParam.LabelContent.PN}】,使用默认角度");
            }


            g.Save();
            g.Dispose();
            string dir = "/image/labeldebug/";
            Directory.CreateDirectory(dir);
            resFile = dir + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".jpg";
            bitmap.Save(resFile, ImageFormat.Jpeg);
            bitmap.Dispose();
            return needRound;
        }
        //public static int CalcLabelAngle(LabelParam labelParam)
        //{
        //    SolidBrush blue = new SolidBrush(Color.Blue);
        //    SolidBrush red = new SolidBrush(Color.Red);
        //    SolidBrush yeelow = new SolidBrush(Color.Yellow);
        //    SolidBrush blueVio = new SolidBrush(Color.BlueViolet);
        //    Font font = new Font(FontFamily.GenericSansSerif, 60);
        //    Pen Greenpen = new Pen(Color.Green, 10);
        //    int codeAngle = 0;
        //    int labelAngle = 0;
        //    string resFile = "";
        //    int needRound = 0;
        //    Bitmap srcbitmap;
        //    if (File.Exists(labelParam.BitmapFilename))
        //    {
        //        srcbitmap = new Bitmap(labelParam.BitmapFilename);
        //    }
        //    else
        //    {
        //        srcbitmap = new Bitmap(labelParam.BitmapWidth, labelParam.BitmapHeight);
        //    }


        //    Bitmap bitmap = new Bitmap(srcbitmap.Width, srcbitmap.Height, PixelFormat.Format32bppArgb);
        //    Graphics g = Graphics.FromImage(bitmap);

        //    g.DrawImage(srcbitmap, 0, 0);
        //    int srcbitmap_Width = srcbitmap.Width;
        //    srcbitmap.Dispose();

        //    //bitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);//格力
        //    // bitmap.RotateFlip(RotateFlipType.Rotate180FlipNone);

        //    Size pointsize = new Size(300, 300);
        //    Point centerPointInImg = new Point(labelParam.TrayCenterInImg_X, labelParam.TrayCenterInImg_Y);
        //    g.FillEllipse(red, new Rectangle(centerPointInImg, pointsize));
        //    CodeInfo codeInfo = labelParam.LabelContent.codeInfos.Find(c => !string.IsNullOrEmpty(labelParam.LabelContent.PN) && c.CodeStr.Contains(labelParam.LabelContent.PN));
        //    labelAngle = 0;//标签角度
        //    int widthOffset;
        //    if (codeInfo != null)
        //    {
        //        Point op = new Point(codeInfo.X, codeInfo.Y);
        //        g.FillEllipse(blue, new Rectangle(op, pointsize));
        //        codeAngle = (int)getAngle(centerPointInImg, op);
        //        widthOffset = (int)distance(centerPointInImg, op);
        //        codeAngle = codeAngle > 0 ? codeAngle : codeAngle + 360;

        //        labelAngle = labelParam.RelativeAngle + codeAngle;
        //        labelAngle = labelAngle > 360 ? labelAngle - 360 : labelAngle;
        //        var p1 = PointWithAngle(centerPointInImg, labelAngle, widthOffset);
        //        g.FillEllipse(yeelow, new Rectangle(p1, pointsize));

        //        needRound = labelParam.RelativeAngle + codeAngle + labelParam.LabelInImgAngle;
        //        needRound = needRound > 360 ? needRound - 360 : needRound;
        //        needRound = needRound > 360 ? needRound - 360 : needRound;

        //        if (needRound > 180)
        //            needRound = needRound - 360;
        //        else if (needRound < -180)
        //        {
        //            needRound = needRound + 360;
        //        }
        //        var p2 = PointWithAngle(centerPointInImg, labelParam.LabelInImgAngle, widthOffset);
        //        g.FillEllipse(blueVio, new Rectangle(p2, pointsize));
        //    }
        //    else
        //    {
        //        LogUtil.error($"贴标未找到料号【{labelParam.LabelContent.PN}】,使用默认角度");
        //    }


        //    g.Save();
        //    g.Dispose();
        //    string dir = "/image/labeldebug/";
        //    Directory.CreateDirectory(dir);
        //    resFile = dir + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".jpg";
        //    bitmap.Save(resFile, ImageFormat.Jpeg);
        //    bitmap.Dispose();
        //    return needRound;
        //}

        public static (string resFile, int codeAngle,int labelAngle,int needRound) CalcLabelAngle(LabelParam labelParam,bool manual)
        {
            SolidBrush blue = new SolidBrush(Color.Blue);
            SolidBrush red = new SolidBrush(Color.Red);
            SolidBrush yeelow = new SolidBrush(Color.Yellow);
            SolidBrush blueVio = new SolidBrush(Color.BlueViolet);
            Font font = new Font(FontFamily.GenericSansSerif, 60);
            Pen Greenpen = new Pen(Color.Green, 10);
            int codeAngle = 0;
            int labelAngle = 0;
            string resFile = "";
            int needRound = 0;
            Bitmap srcbitmap;
            if (File.Exists(labelParam.BitmapFilename))
            {
                srcbitmap = new Bitmap(labelParam.BitmapFilename);
            }
            else
            {
                srcbitmap = new Bitmap(labelParam.BitmapWidth, labelParam.BitmapHeight);
            }


            Bitmap bitmap = new Bitmap(srcbitmap.Width, srcbitmap.Height, PixelFormat.Format32bppArgb);
            Graphics g = Graphics.FromImage(bitmap);

            g.DrawImage(srcbitmap, 0, 0);
            int srcbitmap_Width = srcbitmap.Width;
            srcbitmap.Dispose();

            //bitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);//格力
            // bitmap.RotateFlip(RotateFlipType.Rotate180FlipNone);

            Size pointsize = new Size(300, 300);
            Point centerPointInImg = new Point(labelParam.TrayCenterInImg_X, labelParam.TrayCenterInImg_Y);
            g.FillEllipse(red, new Rectangle(centerPointInImg, pointsize));
            CodeInfo codeInfo = labelParam.LabelContent.codeInfos.Find(c => !string.IsNullOrEmpty(labelParam.LabelContent.PN) && c.CodeStr.Contains(labelParam.LabelContent.PN));
             labelAngle = 0;//标签角度
            int widthOffset;
            if (codeInfo != null)
            {
                Point op = new Point(codeInfo.X, codeInfo.Y);
                g.FillEllipse(blue, new Rectangle(op, pointsize));
                codeAngle = (int)getAngle(centerPointInImg, op);
                widthOffset = (int)distance(centerPointInImg, op);
                codeAngle = codeAngle > 0 ? codeAngle : codeAngle + 360;
                labelParam.RelativeAngle = labelParam.RelativeAngle > 0 ? labelParam.RelativeAngle : labelParam.RelativeAngle + 360;
                labelAngle =labelParam.RelativeAngle + codeAngle;

                labelAngle = labelAngle > 0 ? labelAngle : labelAngle +360;
                var p1 = PointWithAngle(centerPointInImg, labelAngle, widthOffset);
                g.FillEllipse(yeelow, new Rectangle(p1, pointsize));
                labelParam.LabelInImgAngle = labelParam.LabelInImgAngle > 0 ? labelParam.LabelInImgAngle : labelParam.LabelInImgAngle + 360;

                needRound = (labelParam.RelativeAngle- labelParam.LabelInImgAngle) + codeAngle;
                needRound = needRound % 360;
                //needRound = needRound > 360 ? needRound - 360 : needRound;

                if (needRound > 180)
                    needRound = needRound - 360;
                else if (needRound < -180)
                {
                    needRound = needRound + 360;
                }
                var p2 = PointWithAngle(centerPointInImg, labelParam.LabelInImgAngle, widthOffset);
                g.FillEllipse(blueVio, new Rectangle(p2, pointsize));
            }
            else
            {
                LogUtil.error($"贴标未找到料号【{labelParam.LabelContent.PN}】,使用默认角度");
            }


            g.Save();
            g.Dispose();
            string dir = "/image/labeldebug/";
            Directory.CreateDirectory(dir);
            resFile = dir + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".jpg";
            bitmap.Save(resFile, ImageFormat.Jpeg);
            bitmap.Dispose();

            return (resFile,codeAngle,labelAngle,needRound);
        }
        /// <summary>
        /// 计算实际需要贴标的位置
        /// </summary>
        /// <param name="labelParam">标签参数</param>
        /// <returns>实际的贴标位置</returns>
        //public static Point CalcLabelPoint(LabelParam labelParam)
        //{
        //    SolidBrush blue = new SolidBrush(Color.BlueViolet);
        //    SolidBrush red = new SolidBrush(Color.Red);
        //    SolidBrush yeelow = new SolidBrush(Color.Yellow);
        //    SolidBrush AliceBlue = new SolidBrush(Color.AliceBlue);
        //    Font font = new Font(FontFamily.GenericSansSerif, 60);
        //    Pen Greenpen = new Pen(Color.Green, 10);

        //    Bitmap srcbitmap;
        //    if (File.Exists(labelParam.BitmapFilename))
        //    {
        //        srcbitmap = new Bitmap(labelParam.BitmapFilename);
        //    }
        //    else
        //    {
        //        srcbitmap = new Bitmap(labelParam.BitmapWidth, labelParam.BitmapHeight);
        //    }


        //    Bitmap bitmap = new Bitmap(srcbitmap.Width, srcbitmap.Height, PixelFormat.Format32bppArgb);
        //    Graphics g = Graphics.FromImage(bitmap);

        //    g.DrawImage(srcbitmap, 0, 0);
        //    int srcbitmap_Width = srcbitmap.Width;
        //    srcbitmap.Dispose();

        //    //bitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);//格力
        //    bitmap.RotateFlip(RotateFlipType.Rotate180FlipNone);

        //    Size pointsize = new Size(30, 30);
        //    int widthOffset = 0;
        //    Point centerPointInImg = new Point(labelParam.TrayCenterInImg_X, labelParam.TrayCenterInImg_Y);
        //    g.FillEllipse(blue, new Rectangle(centerPointInImg, pointsize));
        //    List<int> angles = new List<int>();
        //    labelParam.LabelContent.codeInfos.ForEach((c) =>
        //    {
        //        //Point op = Common.PointRotate(Right_Batch_Point, new Point(c.X, c.Y), 83d / 180 * Math.PI);
        //        //c.X = op.X;
        //        //c.Y = op.Y;
        //        var x = c.Y;
        //        var y = srcbitmap_Width - c.X;
        //        c.X = x;
        //        c.Y = y;

        //        Point op = new Point(c.X, c.Y);
        //        g.FillEllipse(blue, new Rectangle(op, pointsize));
        //        var a = (int)getAngle(centerPointInImg, op);
        //        //a += ConfigHelper.Config.Get<int>("AngleChange");
        //        a = a < 0 ? 360 + a : a;

        //        //g.FillEllipse(red, new Rectangle(PointRotate(org, op, a), pointsize));
        //        if (c.CodeStr.Contains(labelParam.LabelContent.PN))
        //            angles.Add(a);
        //        widthOffset = (int)distance(centerPointInImg, op);
        //    });
        //    angles.Sort();
        //    //if (angles.Count > 1) {
        //    angles.Add(360 + angles[0]);
        //    //}
        //    int biglen = 0;
        //    int bigangles = 0;
        //    for (int i = 0; i < angles.Count; i++)
        //    {
        //        if (angles.Count() - i < 2)
        //            break;

        //        var x = angles[i + 1] - angles[i];
        //        if (x > biglen)
        //        {
        //            biglen = x;
        //            bigangles = angles[i];
        //        }
        //    }
        //    int labelAngle;//标签角度
        //    if (labelParam.LabelContent.PlateW > 7)
        //    {// && angles.Count==2) {
        //        labelAngle = angles[0] + 120;
        //    }
        //    else
        //    {
        //        //labelAngle = bigangles + biglen / 2;
        //        labelAngle = angles[0] + 180;
        //    }
        //    //匹配照片角度与贴标旋转轴的角度差
        //    labelAngle += labelParam.Label_R_Angle_Diff;

        //    labelAngle = labelAngle > 360 ? labelAngle - 360 : labelAngle;
        //    labelAngle = labelAngle > 360 ? labelAngle - 360 : labelAngle;

        //    //g.FillEllipse(red, new Rectangle(PointRotate(org, op, labelAngle), pointsize));

        //    //贴标坐标
        //    var p2 = PointWithAngle(centerPointInImg, labelAngle, widthOffset);

        //    //贴标偏移
        //    var labelPos = PointWithAngle(p2, labelAngle + 180, labelParam.Label_R_Offset);
        //    //贴标角度,右侧为0度,+180转换到左侧为0度
        //    labelAngle += 180;
        //    labelAngle = labelAngle > 360 ? labelAngle - 360 : labelAngle;

        //    g.FillEllipse(yeelow, new Rectangle(p2, pointsize));
        //    g.FillEllipse(red, new Rectangle(labelPos, pointsize));
        //    g.Save();
        //    g.Dispose();
        //    string dir = "/image/labeldebug/";
        //    Directory.CreateDirectory(dir);

        //    bitmap.Save(dir + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".jpg", ImageFormat.Jpeg);
        //    bitmap.Dispose();

        //    //计算贴标角度R的脉冲值
        //    if (labelAngle > 350)
        //        labelAngle = 350;
        //    int actualRValue = labelParam.AxisR360Pulse / 350 * labelAngle;

        //    //获取贴标的XY位置
        //    //计算像素点位与中心点的差
        //    Point actualPos = new Point(labelPos.X - labelParam.TrayCenterInImg_X, labelPos.Y - labelParam.TrayCenterInImg_Y);
        //    //计算像素*脉冲像素比得到脉冲值+中心点基准脉冲
        //    actualPos.X = (int)(actualPos.X * labelParam.XRatioPulsePixel) + labelParam.DatumXAxis;
        //    actualPos.Y = (int)(actualPos.Y * labelParam.YRatioPulsePixel) + labelParam.DatumYAxis;
        //    return actualPos;
        //}

        static double getAngle(Point pt1, Point pt2)
        {
            double mb_x = pt2.X - pt1.X;
            double mb_y = pt2.Y - pt1.Y;
            double rotation = Math.Atan2(mb_y, mb_x);


            rotation = rotation / Math.PI * 180;
            return rotation;
            //double angle = 360 - rotation + 90;

            //angle = angle < 0 ? 360 + angle : angle;
            //angle = angle % 360;
            //return Math.Floor(angle / 360 * 24);
        }

        static double distance(Point p1, Point p2)
        {
            double result;
            result = Math.Sqrt((p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y));
            return result;
        }
        /// <summary>
        /// 以指定点为中心,测算指定角度,指定长度位置的点
        /// </summary>
        /// <param name="p1">原点</param>
        /// <param name="angle">角度</param>
        /// <param name="distance">距离</param>
        /// <returns></returns>
        static Point PointWithAngle(Point p1, double angle, double distance)
        {
            var x2 = p1.X + distance * Math.Cos(angle / 180 * Math.PI);
            var y2 = p1.Y + distance * Math.Sin(angle / 180 * Math.PI);
            return new Point((int)x2, (int)y2);
        }

        //DeviceLibrary.LabelParam labelParam = new DeviceLibrary.LabelParam();
        //labelParam.codeInfos = new List<CodeLibrary.CodeInfo>();
        //    //##340093060037##01410000441770##012100000224##Q3000
        //    //labelParam.codeInfos.Add(new CodeLibrary.CodeInfo("Y38072732TLP785(D4GHTR6,F         (C                                                   2000A0132G0 2000ZUY0HG1U8501F2A Y0HG1U 2124   2124TWCN          69                                          T2", 0, 0));
        //    //labelParam.codeInfos.Add(new CodeLibrary.CodeInfo("[)>P1PTLV7022DGKR6P2PAQ25000V00333171T0557736ZEW4WTKYD210631T1032393ASH20LRFB21LUSA22LASH23LCHNEG43Z1/260C/UNLIM;//;022121L18087KN01", 0, 0));
        //    labelParam.codeInfos.Add(new CodeLibrary.CodeInfo("99700736000619EM6H38.125008625", 0, 0));
        //    //labelParam.codeInfos.Add(new CodeLibrary.CodeInfo("CK7T0H.125002115", 0, 0));
        //    //labelParam.codeInfos.Add(new CodeLibrary.CodeInfo("Y38073304TLP385(D4GREETRE         (T                                               00003000A0149T 03000WT0HBGCC8210B3F-5595   2009   2009JPTH  00      67                         91432487           02Q", 0, 0));
        //    //labelParam.codeInfos.Add(new CodeLibrary.CodeInfo("01410000441770", 0, 0));
        //    //labelParam.codeInfos.Add(new CodeLibrary.CodeInfo("012100000224", 0, 0));
        //    //labelParam.codeInfos.Add(new CodeLibrary.CodeInfo("Q3000", 0, 0));
        //    labelParam.codeInfos.Add(new CodeLibrary.CodeInfo("340093060037", 0, 0, "Code 128"));

        //    DeviceLibrary.Common.codeProcess(labelParam, out string debugmsg);
        //Console.WriteLine(debugmsg);


        static string[] pnreglist;
        static string[] qtyreglist;
        public static void LoadMatchList()
        {
            pnreglist = File.ReadAllLines("config\\pn.list").ToList().FindAll((s) => { return !string.IsNullOrWhiteSpace(s); }).ToArray();
            qtyreglist = File.ReadAllLines("config\\qty.list").ToList().FindAll((s) => { return !string.IsNullOrWhiteSpace(s); }).ToArray();
        }
        /// <summary>
        /// 是否有有效码
        /// </summary>
        /// <param name="labelParam"></param>
        /// <param name="debugmsg"></param>
        /// <returns></returns>
        public static bool CodeProcess(LabelContent labelParam, out string debugmsg)
        {
            if (pnreglist == null)
                LoadMatchList();

            debugmsg = "";
            List<CodeInfo> newcodeInfos = new List<CodeInfo>();
            labelParam.PN = "";
            foreach (var ci in labelParam.codeInfos.ToArray())
            {
                //string[] pnreglist = new string[] {
                //    @"^P([1-9]\d+)$",
                //    @"^(\d+)$%Code 128",
                //    @"^([1-9]\d{7,9})$"
                //};
                foreach (var qtyreg in pnreglist)
                {
                    var partrules = qtyreg.Split('%');
                    if (partrules.Length == 2)
                    {
                        if (ci.CodeType != partrules[1])
                            break;
                    }
                    var m = Regex.Match(ci.CodeStr, partrules[0]);
                    if (m.Success)
                    {
                        newcodeInfos.Add(ci);
                        //labelParam.codeInfos.Remove(ci);
                        labelParam.PN = m.Groups[1].Value;

                        debugmsg += $"匹配到PN:{labelParam.PN}\r\n命中规则:{qtyreg}\r\n";
                        break;
                    }
                }
                if (!string.IsNullOrEmpty(labelParam.PN))
                    break;
            }

            labelParam.QTY = 0;
            foreach (var ci in labelParam.codeInfos.ToArray())
            {
                //string[] qtyreglist = new string[] {
                //    @"Q(\d{3,5})[^\d]", 
                //    @"^Q(\d{3,5})$",
                //    @"^\w+\.\d([1-9]+0+)[1-9]+\d*$",
                //    @"^.+?;.+?;.+?;(\d{3,5}?);.+?;.+?$",
                //    @"^QUANTITY:(\d*)",
                //    @"^(\d{6})\s",
                //    @"\(\w*\s+(\d+)[a-zA-Z]",
                //};
                foreach (var qtyreg in qtyreglist)
                {
                    var m = Regex.Match(ci.CodeStr, qtyreg);
                    if (m.Success)
                    {
                        newcodeInfos.Add(ci);
                        //labelParam.codeInfos.Remove(ci);
                        if (!int.TryParse(m.Groups[1].Value, out int qty))
                            break;
                        labelParam.QTY = qty;
                        debugmsg += $"匹配到QTY:{labelParam.QTY}\r\n命中规则:{qtyreg}\r\n";
                        break;
                    }
                }
                if (labelParam.QTY > 0)
                    break;
            }

            if (string.IsNullOrEmpty(labelParam.PN) || labelParam.QTY == 0)
                return false;

            //labelParam.codeInfos = newcodeInfos;
            labelParam.FC = "985022";
            labelParam.RI = "AL" + DateTime.Now.ToString("yyMMddHHmmssf");
            labelParam.Batch = DateTime.Now.ToString("MMdd");
            labelParam.WareCode = labelParam.RI;
            LogUtil.info($"匹配成功:{labelParam.PN},{labelParam.QTY},{labelParam.RI}");
            return true;
        }
    }
}