This commit is contained in:
Chenx221 2023-10-05 19:38:35 +08:00
parent 5eac60bd7e
commit 48dbbd8033
5 changed files with 243 additions and 9 deletions

View File

@ -0,0 +1,34 @@
using Newtonsoft.Json;
namespace AsmrManage
{
public class AppConfig
{
public string DatabaseFilePath { get; set; } = string.Empty; //asmr.db 位置
public string DBBrowserPath { get; set; } = string.Empty; //DBBrowser 位置
public int Version { get; set; } = int.MaxValue; //配置版本信息
}
public static class ConfigManager
{
public static void SaveConfig(AppConfig config) //SAVE
{
config.Version = 1;// v1
string configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json");
File.WriteAllText(configFilePath, JsonConvert.SerializeObject(config));
}
public static AppConfig LoadConfig() //LOAD
{
string configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json");
if (File.Exists(configFilePath))
{
string json = File.ReadAllText(configFilePath);
return JsonConvert.DeserializeObject<AppConfig>(json) ?? new AppConfig();
}
return new AppConfig();
}
}
}

View File

@ -12,6 +12,7 @@
<ItemGroup>
<PackageReference Include="EPPlus" Version="6.2.10" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Data.SQLite" Version="1.0.118" />
<PackageReference Include="System.IO" Version="4.3.0" />
</ItemGroup>

View File

@ -49,12 +49,23 @@
button1 = new Button();
tabPage3 = new TabPage();
tabPage4 = new TabPage();
button9 = new Button();
button8 = new Button();
button7 = new Button();
button6 = new Button();
button5 = new Button();
textBox5 = new TextBox();
label6 = new Label();
button4 = new Button();
textBox4 = new TextBox();
label5 = new Label();
tabPage5 = new TabPage();
label1 = new Label();
tabControl1.SuspendLayout();
tabPage2.SuspendLayout();
groupBox2.SuspendLayout();
groupBox1.SuspendLayout();
tabPage4.SuspendLayout();
SuspendLayout();
//
// tabControl1
@ -69,6 +80,7 @@
tabControl1.SelectedIndex = 0;
tabControl1.Size = new Size(536, 424);
tabControl1.TabIndex = 0;
tabControl1.SelectedIndexChanged += TabControl1_SelectedIndexChanged;
//
// tabPage1
//
@ -274,14 +286,113 @@
//
// tabPage4
//
tabPage4.Controls.Add(button9);
tabPage4.Controls.Add(button8);
tabPage4.Controls.Add(button7);
tabPage4.Controls.Add(button6);
tabPage4.Controls.Add(button5);
tabPage4.Controls.Add(textBox5);
tabPage4.Controls.Add(label6);
tabPage4.Controls.Add(button4);
tabPage4.Controls.Add(textBox4);
tabPage4.Controls.Add(label5);
tabPage4.Location = new Point(4, 24);
tabPage4.Name = "tabPage4";
tabPage4.Padding = new Padding(3);
tabPage4.Size = new Size(528, 396);
tabPage4.TabIndex = 3;
tabPage4.Text = "高级功能";
tabPage4.Text = "设置";
tabPage4.UseVisualStyleBackColor = true;
//
// button9
//
button9.Location = new Point(209, 317);
button9.Name = "button9";
button9.Size = new Size(101, 44);
button9.TabIndex = 9;
button9.Text = "重置配置文件";
button9.UseVisualStyleBackColor = true;
button9.Click += button9_Click;
//
// button8
//
button8.Location = new Point(209, 267);
button8.Name = "button8";
button8.Size = new Size(101, 44);
button8.TabIndex = 8;
button8.Text = "保存配置文件";
button8.UseVisualStyleBackColor = true;
button8.Click += button8_Click;
//
// button7
//
button7.Location = new Point(209, 217);
button7.Name = "button7";
button7.Size = new Size(101, 44);
button7.TabIndex = 7;
button7.Text = "读取配置文件";
button7.UseVisualStyleBackColor = true;
button7.Click += Button7_Click;
//
// button6
//
button6.Location = new Point(342, 21);
button6.Name = "button6";
button6.Size = new Size(75, 23);
button6.TabIndex = 6;
button6.Text = "打开文件";
button6.UseVisualStyleBackColor = true;
//
// button5
//
button5.Location = new Point(423, 78);
button5.Name = "button5";
button5.Size = new Size(75, 23);
button5.TabIndex = 5;
button5.Text = "浏览";
button5.UseVisualStyleBackColor = true;
//
// textBox5
//
textBox5.Location = new Point(20, 104);
textBox5.Name = "textBox5";
textBox5.Size = new Size(478, 23);
textBox5.TabIndex = 4;
//
// label6
//
label6.AutoSize = true;
label6.Location = new Point(20, 86);
label6.Name = "label6";
label6.Size = new Size(151, 15);
label6.TabIndex = 3;
label6.Text = "DB Browser for SQLite 位置";
//
// button4
//
button4.Location = new Point(423, 21);
button4.Name = "button4";
button4.Size = new Size(75, 23);
button4.TabIndex = 2;
button4.Text = "浏览";
button4.UseVisualStyleBackColor = true;
//
// textBox4
//
textBox4.Location = new Point(20, 47);
textBox4.Name = "textBox4";
textBox4.Size = new Size(478, 23);
textBox4.TabIndex = 1;
//
// label5
//
label5.AutoSize = true;
label5.Location = new Point(20, 29);
label5.Name = "label5";
label5.Size = new Size(79, 15);
label5.TabIndex = 0;
label5.Text = "asmr.db 位置";
//
// tabPage5
//
tabPage5.Location = new Point(4, 24);
@ -314,6 +425,8 @@
groupBox2.ResumeLayout(false);
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
tabPage4.ResumeLayout(false);
tabPage4.PerformLayout();
ResumeLayout(false);
}
@ -342,5 +455,15 @@
private Label label4;
private TextBox textBox3;
private CheckBox checkBox4;
private Button button6;
private Button button5;
private TextBox textBox5;
private Label label6;
private Button button4;
private TextBox textBox4;
private Label label5;
private Button button9;
private Button button8;
private Button button7;
}
}

View File

@ -6,13 +6,13 @@ namespace AsmrManage
{
public partial class Form1 : Form
{
public Form1()
public Form1() //init
{
InitializeComponent();
}
private void Button1_Click(object sender, EventArgs e)
private void Button1_Click(object sender, EventArgs e) //P2 xlsx文件选框
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Title = "请选择符合的xlsx表格文件";
@ -25,7 +25,7 @@ namespace AsmrManage
}
private void Button2_Click(object sender, EventArgs e)
private void Button2_Click(object sender, EventArgs e) //P2 db文件位置选框
{
FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
folderBrowserDialog1.UseDescriptionForTitle = true;
@ -36,13 +36,13 @@ namespace AsmrManage
}
}
private void Log(string message)
private void Log(string message) //xlsx2db log function
{
logBox1.AppendText(message + Environment.NewLine);
logBox1.ScrollToCaret();
}
private void Button3_Click(object sender, EventArgs e)
private void Button3_Click(object sender, EventArgs e) //xlsx2db 开始处理
{
Log("开始处理");
string excelFilePath = textBox1.Text;
@ -55,7 +55,7 @@ namespace AsmrManage
{
databaseLocation = textBox2.Text;
}
if (string.IsNullOrEmpty(excelFilePath) || string.IsNullOrEmpty(databaseLocation))
{
Log("TextBox1 或 TextBox2 为空,无法继续处理");
@ -162,15 +162,89 @@ namespace AsmrManage
}
});
}
private void CheckBox2_CheckedChanged(object sender, EventArgs e)
private void CheckBox2_CheckedChanged(object sender, EventArgs e) //转换使用源文件位置
{
textBox2.Enabled = !checkBox2.Checked;
button2.Enabled = !checkBox2.Checked;
}
private void CheckBox4_CheckedChanged(object sender, EventArgs e)
private void CheckBox4_CheckedChanged(object sender, EventArgs e) //文件是否受密码保护
{
textBox3.ReadOnly = !checkBox4.Checked;
}
private void TabControl1_SelectedIndexChanged(object sender, EventArgs e) //切换标签页
{
ResetPage2();
ResetPage4();
if (tabControl1.SelectedTab == tabPage4)
{
RefreshSettingPageInfo();
}
}
private void RefreshSettingPageInfo() //重新获取P4信息
{
Program.config ??= ConfigManager.LoadConfig();
textBox4.Text = Program.config.DatabaseFilePath;
textBox5.Text = Program.config.DBBrowserPath;
}
private void ResetPage4()
{
textBox4.Text = string.Empty;
textBox5.Text = string.Empty;
} //刷新P4
private void ResetPage2()
{
// 重置内容
textBox1.Text = string.Empty;
textBox2.Text = string.Empty;
textBox3.Text = string.Empty;
logBox1.Text = string.Empty;
// 取消选中checkBox1~4
checkBox1.Checked = false;
checkBox2.Checked = false;
checkBox3.Checked = false;
checkBox4.Checked = false;
} //刷新P2
private void Button7_Click(object sender, EventArgs e) //读取配置文件
{
Program.config = ConfigManager.LoadConfig();
RefreshSettingPageInfo();
MessageBox.Show("配置信息已重新加载。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void button8_Click(object sender, EventArgs e) //保存配置文件
{
//保存前信息检查
string path1 = textBox4.Text.Trim();
string path2 = textBox5.Text.Trim();
if (!string.IsNullOrEmpty(path1) && !File.Exists(path1))
{
MessageBox.Show("指定的DB路径不存在。请检查路径是否正确。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (!string.IsNullOrEmpty(path2) && !File.Exists(path2))
{
MessageBox.Show("指定的DB Browser路径不存在。请检查路径是否正确。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
//开始保存
Program.config ??= ConfigManager.LoadConfig();
Program.config.DatabaseFilePath = path1;
Program.config.DBBrowserPath = path2;
ConfigManager.SaveConfig(Program.config);
}
private void button9_Click(object sender, EventArgs e) //重置配置文件
{
Program.config = null;
ConfigManager.SaveConfig(new AppConfig());
RefreshSettingPageInfo();
}
}
}

View File

@ -5,11 +5,13 @@ namespace AsmrManage
/// <summary>
/// The main entry point for the application.
/// </summary>
public static AppConfig? config;
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
config = ConfigManager.LoadConfig(); //fetch configuration data
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}