ready for 1.0.0
This commit is contained in:
Chenx221 2023-10-06 19:29:31 +08:00
parent 156da8786d
commit 5f81407694
2 changed files with 229 additions and 51 deletions

View File

@ -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);

View File

@ -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;
}
}
private void button13_Click(object sender, EventArgs e)
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();
}
}
@ -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,13 +513,17 @@ 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);
// 检查备份是否已存在
if (!File.Exists(backupFilePath))
{
string sevenZipPath;
// 判断系统位数
@ -477,12 +563,94 @@ namespace AsmrManage
Logp1("备份失败!");
return;
}
}
else
{
Logp1("今日已备份");
}
}
//开始查找
//pending
//开始查找(根据selectedText选择需要查询的数据表查询keyword是否出现在字段"ID"
//string DbPath = Program.config.DatabaseFilePath;
//keyword
//selectedTextH_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;
}
}
}