From 48dbbd80335d1fe9f81afcba47d1a0caa8cce3a2 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Thu, 5 Oct 2023 19:38:35 +0800 Subject: [PATCH] up --- AsmrManage/AsmrManage/AppConfig.cs | 34 +++++++ AsmrManage/AsmrManage/AsmrManage.csproj | 1 + AsmrManage/AsmrManage/Form1.Designer.cs | 125 +++++++++++++++++++++++- AsmrManage/AsmrManage/Form1.cs | 90 +++++++++++++++-- AsmrManage/AsmrManage/Program.cs | 2 + 5 files changed, 243 insertions(+), 9 deletions(-) create mode 100644 AsmrManage/AsmrManage/AppConfig.cs diff --git a/AsmrManage/AsmrManage/AppConfig.cs b/AsmrManage/AsmrManage/AppConfig.cs new file mode 100644 index 0000000..c3a8229 --- /dev/null +++ b/AsmrManage/AsmrManage/AppConfig.cs @@ -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(json) ?? new AppConfig(); + } + + return new AppConfig(); + } + } + +} diff --git a/AsmrManage/AsmrManage/AsmrManage.csproj b/AsmrManage/AsmrManage/AsmrManage.csproj index 0671b4d..067c3a0 100644 --- a/AsmrManage/AsmrManage/AsmrManage.csproj +++ b/AsmrManage/AsmrManage/AsmrManage.csproj @@ -12,6 +12,7 @@ + diff --git a/AsmrManage/AsmrManage/Form1.Designer.cs b/AsmrManage/AsmrManage/Form1.Designer.cs index cae0864..ff1af30 100644 --- a/AsmrManage/AsmrManage/Form1.Designer.cs +++ b/AsmrManage/AsmrManage/Form1.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/AsmrManage/AsmrManage/Form1.cs b/AsmrManage/AsmrManage/Form1.cs index 0d927d4..83407df 100644 --- a/AsmrManage/AsmrManage/Form1.cs +++ b/AsmrManage/AsmrManage/Form1.cs @@ -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(); + } } } \ No newline at end of file diff --git a/AsmrManage/AsmrManage/Program.cs b/AsmrManage/AsmrManage/Program.cs index 67b50ba..ff8bfac 100644 --- a/AsmrManage/AsmrManage/Program.cs +++ b/AsmrManage/AsmrManage/Program.cs @@ -5,11 +5,13 @@ namespace AsmrManage /// /// The main entry point for the application. /// + 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()); }