提交导表相关功能
This commit is contained in:
141
Tools/ConfigBuilder/NBConfigBuilder/Form1.cs
Normal file
141
Tools/ConfigBuilder/NBConfigBuilder/Form1.cs
Normal file
@@ -0,0 +1,141 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace NBConfigBuilder
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
// 配置文件路径
|
||||
private readonly string configPath =
|
||||
Path.Combine(Path.GetDirectoryName(Application.ExecutablePath) ?? string.Empty, "config.json");
|
||||
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
// 设置窗口大小不可变
|
||||
this.FormBorderStyle = FormBorderStyle.FixedSingle;
|
||||
this.MaximizeBox = false;
|
||||
|
||||
// 加载保存的配置
|
||||
LoadConfig();
|
||||
}
|
||||
|
||||
private void buttonRun_Click(object sender, EventArgs e)
|
||||
{
|
||||
// 保存当前配置
|
||||
SaveConfig();
|
||||
new ExcelExporter(ExportType.AllExcel).Run();
|
||||
}
|
||||
|
||||
private void buttonSelectExcelPath_Click(object sender, EventArgs e)
|
||||
{
|
||||
using (FolderBrowserDialog folderDlg = new FolderBrowserDialog())
|
||||
{
|
||||
folderDlg.Description = "请选择配置表路径";
|
||||
if (folderDlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
textBoxExcelPath.Text = folderDlg.SelectedPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSelectClientJsonPath_Click(object sender, EventArgs e)
|
||||
{
|
||||
using (FolderBrowserDialog folderDlg = new FolderBrowserDialog())
|
||||
{
|
||||
folderDlg.Description = @"选择客户端json保存目录";
|
||||
if (folderDlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
textBoxClientGenJsonPath.Text = folderDlg.SelectedPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSelectServerJsonPath_Click(object sender, EventArgs e)
|
||||
{
|
||||
using (FolderBrowserDialog folderDlg = new FolderBrowserDialog())
|
||||
{
|
||||
folderDlg.Description = @"选择服务端json保存目录";
|
||||
if (folderDlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
textBoxServerGenJsonPath.Text = folderDlg.SelectedPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSelectClientPath_Click(object sender, EventArgs e)
|
||||
{
|
||||
using (FolderBrowserDialog folderDlg = new FolderBrowserDialog())
|
||||
{
|
||||
folderDlg.Description = @"选择客户端代码保存目录";
|
||||
if (folderDlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
textBoxClientGenPath.Text = folderDlg.SelectedPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSelectServerPath_Click(object sender, EventArgs e)
|
||||
{
|
||||
using (FolderBrowserDialog folderDlg = new FolderBrowserDialog())
|
||||
{
|
||||
folderDlg.Description = @"选择服务端代码保存目录";
|
||||
if (folderDlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
textBoxServerGenPath.Text = folderDlg.SelectedPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 添加保存和加载配置的方法
|
||||
private void SaveConfig()
|
||||
{
|
||||
var config = new AppConfig
|
||||
{
|
||||
ExcelPath = textBoxExcelPath.Text,
|
||||
ClientPath = textBoxClientGenPath.Text,
|
||||
ClientJsonPath = textBoxClientGenJsonPath.Text,
|
||||
ServerPath = textBoxServerGenPath.Text,
|
||||
ServerJsonPath = textBoxServerGenJsonPath.Text,
|
||||
GenClient = checkBoxGenClient.Checked,
|
||||
GenServer = checkBoxGenServer.Checked,
|
||||
};
|
||||
App.Config = config;
|
||||
try
|
||||
{
|
||||
string json = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true });
|
||||
File.WriteAllText(configPath, json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"保存配置失败: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadConfig()
|
||||
{
|
||||
if (!File.Exists(configPath)) return;
|
||||
|
||||
try
|
||||
{
|
||||
string json = File.ReadAllText(configPath);
|
||||
var config = JsonSerializer.Deserialize<AppConfig>(json);
|
||||
|
||||
if (config != null)
|
||||
{
|
||||
App.Config = config;
|
||||
textBoxExcelPath.Text = config.ExcelPath ?? "";
|
||||
textBoxClientGenPath.Text = config.ClientPath ?? "";
|
||||
textBoxServerGenPath.Text = config.ServerPath ?? "";
|
||||
checkBoxGenClient.Checked = config.GenClient;
|
||||
checkBoxGenServer.Checked = config.GenServer;
|
||||
textBoxClientGenJsonPath.Text = config.ClientJsonPath ?? "";
|
||||
textBoxServerGenJsonPath.Text = config.ServerJsonPath ?? "";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"加载配置失败: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user