This commit is contained in:
Chenx221 2023-10-04 22:16:51 +08:00
parent f51a5b0937
commit 5eac60bd7e
2 changed files with 37 additions and 2 deletions

View File

@ -196,6 +196,7 @@
checkBox2.TabIndex = 8; checkBox2.TabIndex = 8;
checkBox2.Text = "转换时使用源文件位置"; checkBox2.Text = "转换时使用源文件位置";
checkBox2.UseVisualStyleBackColor = true; checkBox2.UseVisualStyleBackColor = true;
checkBox2.CheckedChanged += CheckBox2_CheckedChanged;
// //
// checkBox1 // checkBox1
// //

View File

@ -1,5 +1,6 @@
using OfficeOpenXml; using OfficeOpenXml;
using System.Data.SQLite; using System.Data.SQLite;
using System.Diagnostics;
namespace AsmrManage namespace AsmrManage
{ {
@ -38,13 +39,23 @@ namespace AsmrManage
private void Log(string message) private void Log(string message)
{ {
logBox1.AppendText(message + Environment.NewLine); logBox1.AppendText(message + Environment.NewLine);
logBox1.ScrollToCaret();
} }
private void Button3_Click(object sender, EventArgs e) private void Button3_Click(object sender, EventArgs e)
{ {
Log("开始处理"); Log("开始处理");
string excelFilePath = textBox1.Text; string excelFilePath = textBox1.Text;
string databaseLocation = textBox2.Text; string? databaseLocation;
if (checkBox2.Checked)
{
databaseLocation = Path.GetDirectoryName(excelFilePath);
}
else
{
databaseLocation = textBox2.Text;
}
if (string.IsNullOrEmpty(excelFilePath) || string.IsNullOrEmpty(databaseLocation)) if (string.IsNullOrEmpty(excelFilePath) || string.IsNullOrEmpty(databaseLocation))
{ {
Log("TextBox1 或 TextBox2 为空,无法继续处理"); Log("TextBox1 或 TextBox2 为空,无法继续处理");
@ -68,6 +79,21 @@ namespace AsmrManage
Log("目标DB文件不存在准备创建"); Log("目标DB文件不存在准备创建");
SQLiteConnection.CreateFile(databasePath); SQLiteConnection.CreateFile(databasePath);
} }
else
{
if (checkBox1.Checked) //allow override
{
Log("文件已存在15s后覆盖已存在的文件如反悔请及时结束程序");
Task.Delay(15000).Wait(); // 延时15秒
File.Delete(databasePath);
SQLiteConnection.CreateFile(databasePath);
}
else
{
Log("文件已存在,当前设定不允许覆盖已有文件,程序退出");
return;
}
}
string connectionString = $"Data Source={databasePath};Version=3;"; string connectionString = $"Data Source={databasePath};Version=3;";
@ -130,13 +156,21 @@ namespace AsmrManage
{ {
Log("SUCCESS"); Log("SUCCESS");
})); }));
if (checkBox3.Checked)
{
Process.Start("explorer.exe", databaseLocation);
}
}); });
} }
private void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
textBox2.Enabled = !checkBox2.Checked;
}
private void CheckBox4_CheckedChanged(object sender, EventArgs e) private void CheckBox4_CheckedChanged(object sender, EventArgs e)
{ {
textBox3.ReadOnly = !checkBox4.Checked; textBox3.ReadOnly = !checkBox4.Checked;
} }
} }
} }