初步实现添加元素的逻辑
parent
c783fee21b
commit
3083e88137
@ -0,0 +1,63 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Nodes;
|
||||||
|
using OMS.NET.DbClass;
|
||||||
|
|
||||||
|
namespace OMS.NET.Common
|
||||||
|
{
|
||||||
|
public class LayerData
|
||||||
|
{
|
||||||
|
public string? TemplateId { get; set; }
|
||||||
|
public long LayerId { get; set; }
|
||||||
|
public bool HasChange { get; set; } = false;
|
||||||
|
public string Type { get; set; }
|
||||||
|
public JsonNode? Members { get; set; }
|
||||||
|
public JsonNode? Structure { get; set; }
|
||||||
|
public int Phase { get; set; } = 1;
|
||||||
|
|
||||||
|
public LayerData(long layerId, string type)
|
||||||
|
{
|
||||||
|
LayerId = layerId;
|
||||||
|
Type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LayerData(string? templateId, MapLayer layer)
|
||||||
|
{
|
||||||
|
TemplateId = templateId;
|
||||||
|
LayerId = layer.Id;
|
||||||
|
Type = layer.Type;
|
||||||
|
Members = (layer.Type == "order") ? JsonNode.Parse(layer.Members) : JsonNode.Parse(Util.Base64ToJson(layer.Members));
|
||||||
|
Structure = string.IsNullOrEmpty(layer.Structure) ? null : JsonNode.Parse(Util.Base64ToJson(layer.Structure));
|
||||||
|
Phase = layer.Phase;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AppendElement(long itemId, string ItemType)
|
||||||
|
{
|
||||||
|
if (this.Type == "order")
|
||||||
|
{
|
||||||
|
GlobalArea.Log.Error($"order图层不能添加{ItemType}元素");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.Members![itemId.ToString()] == null)
|
||||||
|
{
|
||||||
|
this.Members![itemId.ToString()] = ItemType;
|
||||||
|
this.Structure!.AsArray().Add(itemId);
|
||||||
|
this.HasChange = true;
|
||||||
|
//上传图层到数据库
|
||||||
|
MapLayer mapLayer = ConvertToMapLayer();
|
||||||
|
MapLayer.Update(mapLayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapLayer ConvertToMapLayer()
|
||||||
|
{
|
||||||
|
return new MapLayer()
|
||||||
|
{
|
||||||
|
Id = this.LayerId,
|
||||||
|
Type = this.Type,
|
||||||
|
Members = (this.Type == "order") ? this.Members!.ToString() : Util.JsonToBase64(this.Members!.ToString()),
|
||||||
|
Structure = (this.Structure == null) ? "" : Util.JsonToBase64(this.Structure!.ToString()),
|
||||||
|
Phase = this.Phase
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace OMS.NET.Common
|
||||||
|
{
|
||||||
|
public static class Validations
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 验证颜色值是否有效
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="color"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static bool IsHexColor(string color)
|
||||||
|
{
|
||||||
|
// Regex for hex color code (with or without #)
|
||||||
|
var hexColorRegex = new Regex(@"^#?[0-9A-Fa-f]{6}$");
|
||||||
|
return hexColorRegex.IsMatch(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue