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);
|
}
|
}
|
}
|
}
|