2023-07-03 03:02:14 +08:00
|
|
|
using System;
|
2023-07-04 04:08:18 +08:00
|
|
|
using System.Linq;
|
2023-07-03 03:02:14 +08:00
|
|
|
using BITKit;
|
|
|
|
using Godot;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
namespace BITFactory;
|
|
|
|
|
|
|
|
public partial class SearchRegister:Node
|
|
|
|
{
|
|
|
|
[Export] private LineEdit keyLine;
|
|
|
|
[Export] private LineEdit valueLine;
|
|
|
|
[Export] private LineEdit nameLine;
|
|
|
|
[Export] private LineEdit idLine;
|
|
|
|
[Export] private LineEdit registryRecordLine;
|
|
|
|
[Export] private Button registryButton;
|
2023-07-04 04:08:18 +08:00
|
|
|
[Export] private RichTextLabel registryResultLabel;
|
2023-07-03 03:02:14 +08:00
|
|
|
public override void _Ready()
|
|
|
|
{
|
|
|
|
registryButton.Pressed += Create;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Create()
|
|
|
|
{
|
2023-07-04 04:08:18 +08:00
|
|
|
var searchEngine = DI.Get<ISearchEngine>();
|
|
|
|
registryResultLabel.Text = $"正在注册标识";
|
|
|
|
|
|
|
|
var current = searchEngine
|
|
|
|
.GetSearchResults(keyLine.Text)
|
|
|
|
.Where(x=>x.Key == keyLine.Text && x.Id == idLine.Text)
|
|
|
|
;
|
|
|
|
|
|
|
|
SearchResult result=default;
|
|
|
|
|
|
|
|
var searchResults = current as SearchResult[] ?? current.ToArray();
|
|
|
|
if (searchResults.Any())
|
|
|
|
{
|
|
|
|
result = searchResults.First();
|
|
|
|
result.Value = valueLine.Text;
|
|
|
|
result.Display = nameLine.Text;
|
|
|
|
result.RegistryRecord = registryRecordLine.Text;
|
|
|
|
result.UpdateDate = DateTime.Now;
|
|
|
|
|
|
|
|
searchEngine.SaveChanges();
|
|
|
|
|
|
|
|
registryResultLabel.Text = $"标识:{result.Key}已完成更新";
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
2023-07-03 03:02:14 +08:00
|
|
|
{
|
2023-07-04 04:08:18 +08:00
|
|
|
result = new SearchResult()
|
|
|
|
{
|
|
|
|
Key = keyLine.Text,
|
|
|
|
Value = valueLine.Text,
|
|
|
|
Display = nameLine.Text,
|
|
|
|
Id = idLine.Text,
|
|
|
|
RegistryRecord = registryRecordLine.Text,
|
|
|
|
CreateDate = DateTime.Now,
|
|
|
|
UpdateDate = DateTime.Now,
|
|
|
|
};
|
|
|
|
try
|
|
|
|
{
|
|
|
|
registryResultLabel.Text = $"标识:{result.Key}已完成注册";
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
registryResultLabel.Text = $"标识:{result.Key}注册失败,原因:\n{e.Message}";
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
2023-07-03 03:02:14 +08:00
|
|
|
}
|
|
|
|
}
|