This commit is contained in:
CortexCore
2023-07-06 16:32:57 +08:00
parent 82f6504848
commit f4e85d4f9b
20 changed files with 517 additions and 215 deletions

View File

@@ -0,0 +1,180 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Net.Mime;
using BITKit;
using Godot;
using Microsoft.EntityFrameworkCore;
namespace BITFactory;
// ReSharper disable once IdentifierTypo
[Serializable]
public abstract class IDIS_Base
{
/// <summary>
/// 创建时间
/// </summary>
public DateTime CreateDate { get; set; }=DateTime.Now;
/// <summary>
/// 更新时间
/// </summary>
public DateTime UpdateDate { get; set; }=DateTime.Now;
}
// ReSharper disable once IdentifierTypo
/// <summary>
/// 标识的值
/// </summary>
[Serializable]
public class IDIS_Value:IDIS_Base
{
/// <summary>
/// 标识码
/// </summary>
[Key]
public string Handle { get; set; }
}
// ReSharper disable once IdentifierTypo
public class IDIS_Query : IDIS_Value
{
// ReSharper disable once IdentifierTypo
/// <summary>
/// 关联的数据
/// </summary>
public IDIS_Data[] Datas { get; internal set; }
// ReSharper disable once IdentifierTypo
/// <summary>
/// 关联的标识引用
/// </summary>
public IDIS_Reference[] References { get; internal set; }
}
/// <summary>
/// 标识的格式
/// </summary>
[Serializable]
// ReSharper disable once IdentifierTypo
public class IDIS_Data:IDIS_Base
{
/// <summary>
/// 不需要处理这个
/// </summary>
[Key]
public int Index { get; set; }
/// <summary>
/// 标识码
/// </summary>
public string Handle { get; set; }
/// <summary>
/// 值类型,例如string,url,site
/// </summary>
public string Format { get; set; }
/// <summary>
/// 值
/// </summary>
public string Value { get; set; }
}
/// <summary>
/// 标识的引用或关联
/// </summary>
[Serializable]
// ReSharper disable once IdentifierTypo
public class IDIS_Reference:IDIS_Base
{
/// <summary>
/// 不需要处理这个
/// </summary>
[Key]
public int Index{ get; set; }
/// <summary>
/// 标识码
/// </summary>
public string Handle { get; set; }
/// <summary>
/// 相关联的标识
/// </summary>
public string RelatedHandle { get; set; }
}
// ReSharper disable once IdentifierTypo
public class IDIS_DBContext:DbContext
{
/// <summary>
/// 标识表
/// </summary>
private DbSet<IDIS_Value> Values { get; set; }
/// <summary>
/// 标识数据表
/// </summary>
private DbSet<IDIS_Data> Datas{ get; set; }
/// <summary>
/// 标识引用表
/// </summary>
private DbSet<IDIS_Reference> References{ get; set; }
/// <summary>
/// 确保创建数据库
/// </summary>
/// <param name="optionsBuilder"></param>
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// ReSharper disable once StringLiteralTypo
//var sql = SQLiteContextHelper.GetConnectionString("IDIS");
SQLiteContextHelper.GetConnectionSqlAndPath("IDIS",out var sql,out var path);
optionsBuilder.UseSqlite(sql);
BIT4Log.Log<IDIS_DBContext>($"已创建标识数据库:{path}");
}
/// <summary>
/// 查询多个标识
/// </summary>
/// <param name="key">模糊标识码</param>
/// <param name="queries">查询列表</param>
/// <returns>是否查询到了内容</returns>
public bool Query(string key, out IDIS_Query[] queries)
{
var _query = Values.Where(x => x.Handle.Contains(key));
var result = _query.Select(x=>new IDIS_Query()
{
Handle = x.Handle,
CreateDate = x.CreateDate,
UpdateDate = x.UpdateDate,
Datas = Datas.Where(data=>data.Handle == key).ToArray(),
References = References.Where(reference=>reference.Handle == key).ToArray()
});
queries = result.ToArray();
return result.Any();
}
/// <summary>
/// 查询单个标识
/// </summary>
/// <param name="key">模糊标识</param>
/// <param name="query">标识查询结果</param>
/// <returns>是否查询到了标识</returns>
public bool Query(string key, out IDIS_Query query)
{
Query(key, out IDIS_Query[] queries);
query = queries.FirstOrDefault();
var = Datas
//查询相关的标识
.Where(x => x.Handle == "MyHandle")
.OrderBy(x=>x.CreateDate)
//从标识中查找"MyFormat"
.First(x => x.Format == "Temperature").Value;
return queries.Any();
}
}
// ReSharper disable once IdentifierTypo
/// <summary>
/// 标识码注册与查询服务
/// </summary>
public partial class IDIS_Service:Node
{
private static IDIS_DBContext Context;
public override void _Ready()
{
Context = new IDIS_DBContext();
BIT4Log.Log<IDIS_Service>("已创建标识数据库");
Context.Database.EnsureCreated();
}
}

View File

@@ -1,33 +0,0 @@
using Godot;
using System;
namespace BITKit;
[Tool]
public partial class ProductionAnimation : ScriptableAnimation
{
[Export] protected ProgressBar progressBar;
[Export] protected Godot.Collections.Array<NodePath> visibleNodes;
protected override void OnSetValue(float newValue)
{
if (Engine.IsEditorHint()) return;
if (progressBar is null)
{
throw new Exception($"ProgressBar is Null");
}
for (var i = 0; i < visibleNodes.Count; i++)
{
var currentNode =GetNode<Control>( visibleNodes[i]);
var threshold = (i+1) / (float)visibleNodes.Count * 100;
//GD.Print($"当前Node:{currentNode.Name},阈值{threshold} / {newValue}");
if (threshold <= newValue)
{
currentNode.Show();
}
else
{
currentNode.Hide();
}
}
progressBar.Value = newValue;
}
}

View File

@@ -1,44 +0,0 @@
using Godot;
using System;
using System.Linq;
using BITKit;
namespace BITFactory;
public partial class ProductionTraceService : Node
{
private static IDatabaseContext<SearchResult> Context;
[Export] private UXContainer container;
[ExportCategory("快速绑定")]
[Export] private UXContainer searchContainer;
[Export] private Label searchResultLabel;
[Export] private Button submitButton;
[Export] private LineEdit searchInput;
private void Search(string key)
{
Context.TrySearchArray(x=>x.Key.Contains(key) || x.Id.Contains(key) || x.Display.Contains(key), out var result);
switch (result.Length)
{
case > 1:
Entry(result);
break;
case 1:
Entry(result[0]);
break;
}
}
private void Entry(SearchResult result)
{
container.titleLabel.Text = result.Key;
container.Text = result.Display;
}
private void Entry(SearchResult[] results)
{
}
public override void _Ready()
{
Context = new SqlLiteContext<SearchResult>();
BIT4Log.Log<ProductionTraceService>("正在初始化生产追溯服务");
}
}