导表工具修改
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NBConfigBuilder
|
||||
{
|
||||
@@ -7,6 +8,9 @@ namespace NBConfigBuilder
|
||||
// 配置文件路径
|
||||
private readonly string configPath =
|
||||
Path.Combine(Path.GetDirectoryName(Application.ExecutablePath) ?? string.Empty, "config.json");
|
||||
|
||||
// 保存原始标题
|
||||
private string _originalTitle;
|
||||
|
||||
public Form1()
|
||||
{
|
||||
@@ -14,16 +18,64 @@ namespace NBConfigBuilder
|
||||
// 设置窗口大小不可变
|
||||
this.FormBorderStyle = FormBorderStyle.FixedSingle;
|
||||
this.MaximizeBox = false;
|
||||
|
||||
// 保存原始标题
|
||||
_originalTitle = this.Text;
|
||||
|
||||
// 加载保存的配置
|
||||
LoadConfig();
|
||||
}
|
||||
|
||||
private void buttonRun_Click(object sender, EventArgs e)
|
||||
private async void buttonRun_Click(object sender, EventArgs e)
|
||||
{
|
||||
// 保存当前配置
|
||||
SaveConfig();
|
||||
new ExcelExporter(ExportType.AllExcel).Run();
|
||||
// 禁用按钮防止重复点击
|
||||
buttonRun.Enabled = false;
|
||||
buttonRun.Text = "执行中...";
|
||||
|
||||
try
|
||||
{
|
||||
// 保存当前配置
|
||||
SaveConfig();
|
||||
|
||||
// 创建导出器并设置进度回调
|
||||
var exporter = new ExcelExporter(ExportType.AllExcel);
|
||||
exporter.SetProgressCallback(UpdateProgress);
|
||||
|
||||
// 运行导出器
|
||||
await Task.Run(() => exporter.Run());
|
||||
|
||||
// 显示成功消息
|
||||
MessageBox.Show("配置导出完成!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 显示错误消息
|
||||
MessageBox.Show($"导出过程中发生错误:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// 恢复按钮状态和标题
|
||||
buttonRun.Enabled = true;
|
||||
buttonRun.Text = "执行";
|
||||
this.Text = _originalTitle;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新进度显示
|
||||
/// </summary>
|
||||
/// <param name="message">进度消息</param>
|
||||
private void UpdateProgress(string message)
|
||||
{
|
||||
// 确保在UI线程上更新界面
|
||||
if (InvokeRequired)
|
||||
{
|
||||
Invoke(new Action<string>(UpdateProgress), message);
|
||||
return;
|
||||
}
|
||||
|
||||
// 更新标题栏显示进度
|
||||
this.Text = $"{_originalTitle} - {message}";
|
||||
}
|
||||
|
||||
private void buttonSelectExcelPath_Click(object sender, EventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user