56 lines
1.5 KiB
C#
56 lines
1.5 KiB
C#
using System;
|
|
using System.Linq;
|
|
using CadParamPluging.Domain.Models;
|
|
|
|
namespace CadParamPluging.Common
|
|
{
|
|
public static class TemplateKeyBuilder
|
|
{
|
|
public static string Build(TemplateParams tpl)
|
|
{
|
|
if (tpl == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return Build(tpl.ProjectType, tpl.DrawingType, tpl.SheetSize, tpl.Scale);
|
|
}
|
|
|
|
public static string Build(string projectType, string drawingType, string sheetSize, string scale)
|
|
{
|
|
var p1 = NormalizeValue(projectType);
|
|
var p2 = NormalizeValue(drawingType);
|
|
var p3 = NormalizeValue(sheetSize);
|
|
var p4 = NormalizeScale(scale);
|
|
return string.Join("|", new[] { p1, p2, p3, p4 });
|
|
}
|
|
|
|
private static string NormalizeScale(string s)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(s))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
if (string.Equals(s.Trim(), "无", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
return NormalizeValue(s);
|
|
}
|
|
|
|
private static string NormalizeValue(string s)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(s))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
var trimmed = s.Trim();
|
|
var chars = trimmed.Where(c => !char.IsWhiteSpace(c)).ToArray();
|
|
return new string(chars);
|
|
}
|
|
}
|
|
}
|