From 5f814076946e087d7f75a98de936af142e487021 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Fri, 6 Oct 2023 19:29:31 +0800 Subject: [PATCH] update ready for 1.0.0 --- AsmrManage/AsmrManage/Form1.Designer.cs | 8 +- AsmrManage/AsmrManage/Form1.cs | 272 +++++++++++++++++++----- 2 files changed, 229 insertions(+), 51 deletions(-) diff --git a/AsmrManage/AsmrManage/Form1.Designer.cs b/AsmrManage/AsmrManage/Form1.Designer.cs index 5e88033..3dee3c0 100644 --- a/AsmrManage/AsmrManage/Form1.Designer.cs +++ b/AsmrManage/AsmrManage/Form1.Designer.cs @@ -176,9 +176,9 @@ label11.AutoSize = true; label11.Location = new Point(36, 160); label11.Name = "label11"; - label11.Size = new Size(62, 15); + label11.Size = new Size(36, 15); label11.TabIndex = 14; - label11.Text = "查找结果:"; + label11.Text = "结果:"; // // label10 // @@ -237,6 +237,7 @@ textBox6.Name = "textBox6"; textBox6.Size = new Size(281, 23); textBox6.TabIndex = 7; + textBox6.TextChanged += textBox6_TextChanged; // // label9 // @@ -997,7 +998,10 @@ AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(560, 448); Controls.Add(tabControl1); + FormBorderStyle = FormBorderStyle.FixedSingle; + MaximizeBox = false; Name = "Form1"; + StartPosition = FormStartPosition.CenterScreen; Text = "AsmrManage"; tabControl1.ResumeLayout(false); tabPage1.ResumeLayout(false); diff --git a/AsmrManage/AsmrManage/Form1.cs b/AsmrManage/AsmrManage/Form1.cs index f8b100b..477ae3e 100644 --- a/AsmrManage/AsmrManage/Form1.cs +++ b/AsmrManage/AsmrManage/Form1.cs @@ -3,6 +3,7 @@ using DiffPlex.DiffBuilder; using OfficeOpenXml; using System.Data.SQLite; using System.Diagnostics; +using System.Text.RegularExpressions; namespace AsmrManage { @@ -176,6 +177,7 @@ namespace AsmrManage private void TabControl1_SelectedIndexChanged(object sender, EventArgs e) //Çл»±êÇ©Ò³ { + ResetPage1(); ResetPage2(); ResetPage3(); ResetPage4(); @@ -230,6 +232,19 @@ namespace AsmrManage checkBox4.Checked = false; } //Ë¢ÐÂP2 + private void ResetPage1() //Ë¢ÐÂP1 + { + textBox6.Text = string.Empty; + comboBox1.SelectedItem = null; + label12.Text = string.Empty; + checkBox5.Checked = false; + checkBox6.Checked = false; + checkBox7.Checked = false; + checkBox8.Checked = false; + richTextBox1.Text = string.Empty; + button13.Enabled = false; + } + private void Button7_Click(object sender, EventArgs e) //¶ÁÈ¡ÅäÖÃÎļþ { Program.config = ConfigManager.LoadConfig(); @@ -320,13 +335,80 @@ namespace AsmrManage } } - private void button10_Click(object sender, EventArgs e) + private void button13_Click(object sender, EventArgs e) //Ìí¼Ó { + Program.config = ConfigManager.LoadConfig(); + string DbPath = Program.config.DatabaseFilePath; + string keyword = textBox6.Text.Trim().ToUpper(); + string? selectedText = comboBox1.SelectedItem.ToString(); + if (selectedText == "Auto") + { + if (keyword.StartsWith("RJ")) + { + selectedText = "H_RJ"; + } + else if (keyword.StartsWith("D")) + { + selectedText = "H_D"; + } + else if (keyword.StartsWith("VJ")) + { + selectedText = "H_VJ"; + } + else + { + Logp1("ÎÞ·¨×Ô¶¯¼ì²âÀàÐÍ"); + return; + } + } + bool Feature_Auto_Clear = checkBox6.Checked; //Ìí¼Óºó×Ô¶¯Çå¿ÕÊäÈë¿ò + string connectionString = $"Data Source={DbPath};Version=3"; // SQLiteÊý¾Ý¿âÁ¬½Ó×Ö·û´® + using (SQLiteConnection connection = new SQLiteConnection(connectionString)) + { + connection.Open(); + if (label12.Text == "²»´æÔÚ") + { + // ¿ªÊ¼Ìí¼Ó¼Ç¼ + string number = string.Empty; + foreach (char c in keyword) + { + if (char.IsDigit(c)) + { + number += c; + } + else if (number.Length > 0) + { + // ÒѾ­ÌáÈ¡µ½Êý×Ö²¿·Ö£¬Óöµ½·ÇÊý×Ö×Ö·ûÔòÍ£Ö¹ÌáÈ¡ + break; + } + } - } + if (int.TryParse(number, out int asmr_order_id)) + { + using (SQLiteCommand addCommand = new SQLiteCommand($"INSERT INTO {selectedText} (asmr_id, asmr_order_id) VALUES (@asmr_id, @asmr_order_id)", connection)) + { + addCommand.Parameters.AddWithValue("@asmr_id", keyword); + addCommand.Parameters.AddWithValue("@asmr_order_id", asmr_order_id); + addCommand.ExecuteNonQuery(); - private void button13_Click(object sender, EventArgs e) - { + // Ìí¼Ó³É¹¦ºóµÄÂß¼­ + label12.Text = "³É¹¦"; + Logp1($"{keyword} Òѳɹ¦Ìí¼Óµ½ {selectedText} ±í"); + if (Feature_Auto_Clear) + { + textBox6.Text = string.Empty; + } + } + } + else + { + // ÎÞ·¨ÌáÈ¡Êý×Ö²¿·ÖµÄÇé¿ö + Logp1("ÎÞ·¨ÌáÈ¡Êý×Ö²¿·Ö£¬Ìí¼Óʧ°Ü"); + } + + } + connection.Close(); + } } @@ -345,7 +427,7 @@ namespace AsmrManage string keyword = textBox6.Text.Trim(); string pattern = "^(RJ|VJ|D)[0-9]+$"; // Æ¥ÅäÒÔRJ¡¢VJ¡¢D¿ªÍ·£¬ºó¸úÊý×ÖµÄģʽ - if (System.Text.RegularExpressions.Regex.IsMatch(keyword, pattern)) + if (Regex.IsMatch(keyword, pattern)) { keyword = keyword.ToUpper(); // ½«¹Ø¼ü´ÊתΪ´óд } @@ -358,7 +440,7 @@ namespace AsmrManage //ÏÖÖ§³ÖAuto,H_RJ,H_D,H_VJ,NonH_RJ //ÆäÖÐAuto²»Ö§³ÖNonH_RJ object selectedValue = comboBox1.SelectedItem; - string selectedText; + string? selectedText; if (selectedValue != null) { selectedText = selectedValue.ToString(); @@ -431,58 +513,144 @@ namespace AsmrManage { // ´´½¨±¸·ÝĿ¼ string backupDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "backup"); - if (!Directory.Exists(backupDir)){ + if (!Directory.Exists(backupDir)) + { Directory.CreateDirectory(backupDir); } // ¹¹Ô챸·ÝÎļþÃû£¨Ê¹ÓÃÈÕÆÚʱ¼ä×÷ΪÎļþÃû£© - string backupFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".7z"; + string backupFileName = DateTime.Now.ToString("yyyyMMdd") + ".7z"; string backupFilePath = Path.Combine(backupDir, backupFileName); - string sevenZipPath; - - // ÅжÏϵͳλÊý - if (Environment.Is64BitOperatingSystem) + // ¼ì²é±¸·ÝÊÇ·ñÒÑ´æÔÚ + if (!File.Exists(backupFilePath)) { - sevenZipPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "x64", "7za.exe"); + string sevenZipPath; + + // ÅжÏϵͳλÊý + if (Environment.Is64BitOperatingSystem) + { + sevenZipPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "x64", "7za.exe"); + } + else + { + sevenZipPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "7za.exe"); + } + + if (!File.Exists(sevenZipPath)) + { + Logp1("´íÎ󣬶ªÊ§7za.exeÎļþ"); + return; + } + + + // Ö´Ðб¸·Ý + ProcessStartInfo processInfo = new ProcessStartInfo(); + processInfo.FileName = sevenZipPath; // 7-ZipµÄ¿ÉÖ´ÐÐÎļþ·¾¶ + processInfo.Arguments = $"a -mx9 \"{backupFilePath}\" \"{DbPath}\""; // Ö´ÐÐ7zѹËõÃüÁî + + Process process = new Process(); + process.StartInfo = processInfo; + process.Start(); + process.WaitForExit(); + + // ¼ì²é±¸·ÝÊÇ·ñ³É¹¦ + if (File.Exists(backupFilePath)) + { + Logp1($"×Ô¶¯±¸·Ý³É¹¦£¡Êý¾Ý¿âÒѱ¸·ÝÖÁ{backupFilePath}"); + } + else + { + Logp1("±¸·Ýʧ°Ü£¡"); + return; + } } else { - sevenZipPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "7za.exe"); + Logp1("½ñÈÕÒѱ¸·Ý"); } - - if (!File.Exists(sevenZipPath)) - { - Logp1("´íÎ󣬶ªÊ§7za.exeÎļþ"); - return; - } - - - // Ö´Ðб¸·Ý - ProcessStartInfo processInfo = new ProcessStartInfo(); - processInfo.FileName = sevenZipPath; // 7-ZipµÄ¿ÉÖ´ÐÐÎļþ·¾¶ - processInfo.Arguments = $"a -mx9 \"{backupFilePath}\" \"{DbPath}\""; // Ö´ÐÐ7zѹËõÃüÁî - - Process process = new Process(); - process.StartInfo = processInfo; - process.Start(); - process.WaitForExit(); - - // ¼ì²é±¸·ÝÊÇ·ñ³É¹¦ - if (File.Exists(backupFilePath)) - { - Logp1($"×Ô¶¯±¸·Ý³É¹¦£¡Êý¾Ý¿âÒѱ¸·ÝÖÁ{backupFilePath}"); - } - else - { - Logp1("±¸·Ýʧ°Ü£¡"); - return; - } - } - //¿ªÊ¼²éÕÒ - //pending + //¿ªÊ¼²éÕÒ(¸ù¾ÝselectedTextÑ¡ÔñÐèÒª²éѯµÄÊý¾Ý±í£¬²éѯkeywordÊÇ·ñ³öÏÖÔÚ×Ö¶Î"ID" + //string DbPath = Program.config.DatabaseFilePath; + //keyword + //selectedText£ºH_RJ,H_D,H_VJ,NonH_RJ + //¶ÔÓ¦±í£ºH_RJ,H_D,H_VJ,NonH_RJ + QueryDB(DbPath, keyword, selectedText, Feature_Auto_Add, Feature_Auto_Clear); + } + private void QueryDB(string DbPath, string keyword, string selectedText, bool Feature_Auto_Add, bool Feature_Auto_Clear) + { + string connectionString = $"Data Source={DbPath};Version=3"; // SQLiteÊý¾Ý¿âÁ¬½Ó×Ö·û´® + using (SQLiteConnection connection = new SQLiteConnection(connectionString)) + { + connection.Open(); + + using (SQLiteCommand command = new SQLiteCommand($"SELECT COUNT(*) FROM {selectedText} WHERE asmr_id = @keyword", connection)) + { + command.Parameters.AddWithValue("@keyword", keyword); + + int count = Convert.ToInt32(command.ExecuteScalar()); + button13.Enabled = false; + if (count == 1) + { + label12.Text = "ÒÑ´æÔÚ"; + Logp1($"{keyword}ÒÑ´æÔÚ"); + } + else if (count <= 0) + { + label12.Text = "²»´æÔÚ"; + button13.Enabled = true; + Logp1($"{keyword}²»´æÔÚ"); + } + else + { + label12.Text = "ÒÑ´æÔÚÇÒÖظ´"; + Logp1($"Òì³££¬{keyword}²»´æÔÚ"); + } + } + if (Feature_Auto_Add && label12.Text == "²»´æÔÚ") + { + // ¿ªÊ¼Ìí¼Ó¼Ç¼ + string number = string.Empty; + foreach (char c in keyword) + { + if (char.IsDigit(c)) + { + number += c; + } + else if (number.Length > 0) + { + // ÒѾ­ÌáÈ¡µ½Êý×Ö²¿·Ö£¬Óöµ½·ÇÊý×Ö×Ö·ûÔòÍ£Ö¹ÌáÈ¡ + break; + } + } + + if (int.TryParse(number, out int asmr_order_id)) + { + using (SQLiteCommand addCommand = new SQLiteCommand($"INSERT INTO {selectedText} (asmr_id, asmr_order_id) VALUES (@asmr_id, @asmr_order_id)", connection)) + { + addCommand.Parameters.AddWithValue("@asmr_id", keyword); + addCommand.Parameters.AddWithValue("@asmr_order_id", asmr_order_id); + addCommand.ExecuteNonQuery(); + + // Ìí¼Ó³É¹¦ºóµÄÂß¼­ + label12.Text = "³É¹¦"; + Logp1($"{keyword} Òѳɹ¦Ìí¼Óµ½ {selectedText} ±í"); + if (Feature_Auto_Clear) + { + textBox6.Text = string.Empty; + } + } + } + else + { + // ÎÞ·¨ÌáÈ¡Êý×Ö²¿·ÖµÄÇé¿ö + Logp1("ÎÞ·¨ÌáÈ¡Êý×Ö²¿·Ö£¬Ìí¼Óʧ°Ü"); + } + + } + connection.Close(); + } } private void button17_Click(object sender, EventArgs e) //P3 ¶ÁÈ¡ÐÅÏ¢ @@ -727,14 +895,20 @@ namespace AsmrManage } } - private void button16_Click(object sender, EventArgs e) //Çå¿Õp1²éÕҹؼü´Ê¿ò + private void button16_Click(object sender, EventArgs e) //Çå¿Õp3ÈÕÖ¾ { - richTextBox2.Text = String.Empty; + richTextBox2.Text = string.Empty; } - private void button14_Click(object sender, EventArgs e) + private void button14_Click(object sender, EventArgs e) //Çå¿Õp1ÈÕÖ¾ { - textBox6.Text = String.Empty; + textBox6.Text = string.Empty; + } + + private void textBox6_TextChanged(object sender, EventArgs e) //µ±keyword¸Ä±äʱ + { + button13.Enabled = false; + label12.Text = string.Empty; } } } \ No newline at end of file