alielie
2026-06-15 f08871fe7d148d667f2f11f80f64de71a0d9504c
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
using HMI.Core.Entity;
using HMI.Core.Manager;
using Plugin.TestResult.Util;
using Plugin.TestResult_WPF.Model;
using System;
using System.Linq;
 
namespace Plugin.TestResult_WPF.Util
{
    public class ModelCodeParser : ICodeParser
    {
        public CellInfo GetCellInfoByCode(string code)
        {
            string[] arr = code.Split('-');
            if (arr == null || arr.Length != 3)
            {
                throw new Exception("扫码格式异常");
            }
            return new CellInfo()
            {
                OriginCode = code,
                MachineName = arr[0],
                OvenName = arr[1],
                Index = int.Parse(arr[2]) - 1,
            };
        }
 
        public CellInfo GetCellInfoByCode(string model, int columns, int rows, string code)
        {
            var list = ProductManager.GetParametersByProductName(model);
            ParameterData config = null;
            if (list != null && list.Count > 0)
            {
                config = list.Where(e => e.Name == "PositionCodeConfig").FirstOrDefault();
            }
            if (string.IsNullOrEmpty(config?.Value))
            {
                // 产品没有就按默认的去配
                config = ParameterManager.GetCommonParameterByName("PositionCodeConfig");
                if (string.IsNullOrEmpty(config?.Value))
                {
                    throw new Exception($"当前型号[{model}]未配置穴位规则");
                }
            }
            string value = config.Value;
            string[] arr = value?.Split(';');
            try
            {
                if (arr.Length == 2)
                {
                    string[] v1s = arr[0].Split(',');
                    string[] v2s = arr[1].Split(',');
 
                    return new CellInfo
                    {
                        OriginCode = code,
                        OvenName = code.Substring(int.Parse(v1s[0]), int.Parse(v1s[1])),
                        Index = int.Parse(code.Substring(int.Parse(v2s[0]), int.Parse(v2s[1]))) - 1
                    };
                }
                else if (arr.Length == 3)
                {
                    string[] v1s = arr[0].Split(',');
                    string[] v2s = arr[1].Split(',');
                    string[] v3s = arr[2].Split(',');
 
                    int row = int.Parse(code.Substring(int.Parse(v2s[0]), int.Parse(v2s[1])));
                    int index = int.Parse(code.Substring(int.Parse(v3s[0]), int.Parse(v3s[1])));
 
                    return new CellInfo()
                    {
                        OriginCode = code,
                        OvenName = code.Substring(int.Parse(v1s[0]), int.Parse(v1s[1])),
                        Index = (row - 1) * columns + (index - 1),
                    };
                }
                else if (arr.Length >= 4)
                {
                    string[] v1s = arr[0].Split(',');
                    string[] v2s = arr[1].Split(',');
                    string[] v3s = arr[2].Split(',');
                    columns = int.Parse(arr[3]);
                    int row = int.Parse(code.Substring(int.Parse(v2s[0]), int.Parse(v2s[1])));
                    int index = int.Parse(code.Substring(int.Parse(v3s[0]), int.Parse(v3s[1])));
                    return new CellInfo()
                    {
                        OriginCode = code,
                        OvenName = code.Substring(int.Parse(v1s[0]), int.Parse(v1s[1])),
                        Index = (row - 1) * columns + (index - 1),
                    };
                }
                throw new Exception($"当前型号[{model}]穴位规则配置异常");
            }
            catch (Exception ex)
            {
                throw new Exception($"当前型号[{model}]解析异常:{ex.Message}", ex);
            }
        }
    }
}