implement readonly ExcelEditorForm

This commit is contained in:
mkbka 2024-06-03 13:21:45 +08:00
parent c2da3d21d2
commit 4d74a64180
3 changed files with 72 additions and 10 deletions

View File

@ -30,14 +30,14 @@
{
downloadButton = new Button();
reloadButton = new Button();
propertyGrid1 = new PropertyGrid();
propGrid = new PropertyGrid();
splitContainer1 = new SplitContainer();
splitContainer2 = new SplitContainer();
tableListView = new ListView();
columnHeader1 = new ColumnHeader();
itemListView = new ListView();
button1 = new Button();
columnHeader2 = new ColumnHeader();
button1 = new Button();
((System.ComponentModel.ISupportInitialize)splitContainer1).BeginInit();
splitContainer1.Panel1.SuspendLayout();
splitContainer1.Panel2.SuspendLayout();
@ -68,13 +68,13 @@
reloadButton.UseVisualStyleBackColor = true;
reloadButton.Click += reloadButton_Click;
//
// propertyGrid1
// propGrid
//
propertyGrid1.Dock = DockStyle.Fill;
propertyGrid1.Location = new Point(0, 0);
propertyGrid1.Name = "propertyGrid1";
propertyGrid1.Size = new Size(695, 831);
propertyGrid1.TabIndex = 4;
propGrid.Dock = DockStyle.Fill;
propGrid.Location = new Point(0, 0);
propGrid.Name = "propGrid";
propGrid.Size = new Size(695, 831);
propGrid.TabIndex = 4;
//
// splitContainer1
//
@ -88,7 +88,7 @@
//
// splitContainer1.Panel2
//
splitContainer1.Panel2.Controls.Add(propertyGrid1);
splitContainer1.Panel2.Controls.Add(propGrid);
splitContainer1.Size = new Size(1048, 831);
splitContainer1.SplitterDistance = 349;
splitContainer1.TabIndex = 5;
@ -142,9 +142,12 @@
itemListView.TabIndex = 0;
itemListView.UseCompatibleStateImageBehavior = false;
itemListView.View = View.Details;
itemListView.SelectedIndexChanged += itemListView_SelectedIndexChanged;
//
// button1
//
button1.Anchor = AnchorStyles.Top | AnchorStyles.Right;
button1.Enabled = false;
button1.Location = new Point(872, 12);
button1.Name = "button1";
button1.Size = new Size(188, 44);
@ -179,7 +182,7 @@
private Button downloadButton;
private Button reloadButton;
private PropertyGrid propertyGrid1;
private PropertyGrid propGrid;
private SplitContainer splitContainer1;
private SplitContainer splitContainer2;
private ListView tableListView;

View File

@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@ -27,6 +28,7 @@ namespace SCHALE.Toolbox.Forms
private readonly ExcelTableService _tableService;
private readonly ILogger<ExcelEditorForm> _logger;
private string _excelDirectory;
private IList? _currentExcelTable = null;
public ExcelEditorForm()
{
@ -60,7 +62,63 @@ namespace SCHALE.Toolbox.Forms
private void tableListView_SelectedIndexChanged(object sender, EventArgs e)
{
var selectedItems = tableListView.SelectedItems;
if (selectedItems.Count < 1) return;
var type = selectedItems[0].Tag as Type;
if (type == null) return;
var fbPath = Path.Join(_excelDirectory, $"{type.Name.ToLower()}.fb");
if (!File.Exists(fbPath))
{
_logger.LogError("Decrypted flatbuffer for {Type} not found", type);
return;
}
var bytes = File.ReadAllBytes(fbPath);
var inst = type.GetMethod($"GetRootAs{type.Name}", BindingFlags.Static | BindingFlags.Public,
[typeof(ByteBuffer)])!.Invoke(null, [new ByteBuffer(bytes)]);
var obj = type.GetMethod("UnPack", BindingFlags.Instance | BindingFlags.Public)!.Invoke(inst, null);
var dataList =
obj!.GetType().GetProperty("DataList", BindingFlags.Instance | BindingFlags.Public)!.GetMethod!.Invoke(obj, null)!;
Type? itemType = null;
foreach (var iType in dataList!.GetType().GetInterfaces())
{
if (iType.IsGenericType && iType.GetGenericTypeDefinition() == typeof(IList<>))
{
itemType = iType.GetGenericArguments()[0];
break;
}
}
if (itemType == null)
{
_logger.LogError("Unknown type error");
return;
}
_currentExcelTable = dataList as IList;
_logger.LogInformation("{Count} {TypeName} found", _currentExcelTable!.Count, itemType.Name);
itemListView.Items.Clear();
for (var i = 0; i < _currentExcelTable!.Count; i++)
{
var listItem = new ListViewItem($"{i}");
listItem.Tag = _currentExcelTable[i];
itemListView.Items.Add(listItem);
}
itemListView.Columns[0].Width = -1;
}
private void itemListView_SelectedIndexChanged(object sender, EventArgs e)
{
var selectedItems = itemListView.SelectedItems;
if (selectedItems.Count < 1) return;
var obj = selectedItems[0].Tag;
if (obj == null) return;
propGrid.SelectedObject = obj;
}
private void ReloadExcels()

View File

@ -94,6 +94,7 @@
// exportButton
//
exportButton.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
exportButton.Enabled = false;
exportButton.Location = new Point(289, 3);
exportButton.Name = "exportButton";
exportButton.Size = new Size(280, 59);