diff --git a/AsmrManage/AsmrManage/AsmrManage.csproj b/AsmrManage/AsmrManage/AsmrManage.csproj index b57c89e..0671b4d 100644 --- a/AsmrManage/AsmrManage/AsmrManage.csproj +++ b/AsmrManage/AsmrManage/AsmrManage.csproj @@ -2,10 +2,33 @@ WinExe - net6.0-windows + net6.0-windows10.0.19041.0 enable true enable + 10.0.19041.0 + AsmrManage.Program + + + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/AsmrManage/AsmrManage/Form1.Designer.cs b/AsmrManage/AsmrManage/Form1.Designer.cs index 249102e..fd55a4d 100644 --- a/AsmrManage/AsmrManage/Form1.Designer.cs +++ b/AsmrManage/AsmrManage/Form1.Designer.cs @@ -31,10 +31,30 @@ tabControl1 = new TabControl(); tabPage1 = new TabPage(); tabPage2 = new TabPage(); + groupBox2 = new GroupBox(); + logBox1 = new RichTextBox(); + groupBox1 = new GroupBox(); + textBox3 = new TextBox(); + checkBox4 = new CheckBox(); + label4 = new Label(); + checkBox3 = new CheckBox(); + button3 = new Button(); + checkBox2 = new CheckBox(); + checkBox1 = new CheckBox(); + textBox2 = new TextBox(); + button2 = new Button(); + label3 = new Label(); + label2 = new Label(); + textBox1 = new TextBox(); + button1 = new Button(); tabPage3 = new TabPage(); tabPage4 = new TabPage(); tabPage5 = new TabPage(); + label1 = new Label(); tabControl1.SuspendLayout(); + tabPage2.SuspendLayout(); + groupBox2.SuspendLayout(); + groupBox1.SuspendLayout(); SuspendLayout(); // // tabControl1 @@ -47,7 +67,7 @@ tabControl1.Location = new Point(12, 12); tabControl1.Name = "tabControl1"; tabControl1.SelectedIndex = 0; - tabControl1.Size = new Size(776, 426); + tabControl1.Size = new Size(536, 424); tabControl1.TabIndex = 0; // // tabPage1 @@ -55,27 +75,198 @@ tabPage1.Location = new Point(4, 24); tabPage1.Name = "tabPage1"; tabPage1.Padding = new Padding(3); - tabPage1.Size = new Size(768, 398); + tabPage1.Size = new Size(528, 396); tabPage1.TabIndex = 0; tabPage1.Text = "查询&修改"; tabPage1.UseVisualStyleBackColor = true; // // tabPage2 // + tabPage2.Controls.Add(groupBox2); + tabPage2.Controls.Add(groupBox1); tabPage2.Location = new Point(4, 24); tabPage2.Name = "tabPage2"; tabPage2.Padding = new Padding(3); - tabPage2.Size = new Size(768, 398); + tabPage2.Size = new Size(528, 396); tabPage2.TabIndex = 1; tabPage2.Text = "DB数据库转换"; tabPage2.UseVisualStyleBackColor = true; // + // groupBox2 + // + groupBox2.BackColor = Color.Black; + groupBox2.Controls.Add(logBox1); + groupBox2.ForeColor = SystemColors.HighlightText; + groupBox2.Location = new Point(6, 186); + groupBox2.Name = "groupBox2"; + groupBox2.Size = new Size(516, 204); + groupBox2.TabIndex = 1; + groupBox2.TabStop = false; + groupBox2.Text = "Log"; + // + // logBox1 + // + logBox1.BackColor = Color.Black; + logBox1.BorderStyle = BorderStyle.None; + logBox1.ForeColor = Color.White; + logBox1.Location = new Point(6, 22); + logBox1.Name = "logBox1"; + logBox1.ReadOnly = true; + logBox1.Size = new Size(504, 163); + logBox1.TabIndex = 0; + logBox1.Text = ""; + // + // groupBox1 + // + groupBox1.Controls.Add(textBox3); + groupBox1.Controls.Add(checkBox4); + groupBox1.Controls.Add(label4); + groupBox1.Controls.Add(checkBox3); + groupBox1.Controls.Add(button3); + groupBox1.Controls.Add(checkBox2); + groupBox1.Controls.Add(checkBox1); + groupBox1.Controls.Add(textBox2); + groupBox1.Controls.Add(button2); + groupBox1.Controls.Add(label3); + groupBox1.Controls.Add(label2); + groupBox1.Controls.Add(textBox1); + groupBox1.Controls.Add(button1); + groupBox1.Location = new Point(6, 6); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(516, 174); + groupBox1.TabIndex = 0; + groupBox1.TabStop = false; + groupBox1.Text = "xlsx→sqlite db"; + // + // textBox3 + // + textBox3.Location = new Point(82, 94); + textBox3.Name = "textBox3"; + textBox3.ReadOnly = true; + textBox3.Size = new Size(138, 23); + textBox3.TabIndex = 13; + textBox3.UseSystemPasswordChar = true; + // + // checkBox4 + // + checkBox4.AutoSize = true; + checkBox4.Location = new Point(226, 96); + checkBox4.Name = "checkBox4"; + checkBox4.Size = new Size(117, 19); + checkBox4.TabIndex = 12; + checkBox4.Text = "文件受密码保护"; + checkBox4.UseVisualStyleBackColor = true; + checkBox4.CheckedChanged += CheckBox4_CheckedChanged; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(6, 97); + label4.Name = "label4"; + label4.Size = new Size(70, 15); + label4.TabIndex = 11; + label4.Text = "密码(可选):"; + // + // checkBox3 + // + checkBox3.AutoSize = true; + checkBox3.Location = new Point(360, 146); + checkBox3.Name = "checkBox3"; + checkBox3.Size = new Size(117, 19); + checkBox3.TabIndex = 10; + checkBox3.Text = "完成时显示文件"; + checkBox3.UseVisualStyleBackColor = true; + // + // button3 + // + button3.Location = new Point(157, 123); + button3.Name = "button3"; + button3.Size = new Size(186, 44); + button3.TabIndex = 9; + button3.Text = "开始转换"; + button3.UseVisualStyleBackColor = true; + button3.Click += Button3_Click; + // + // checkBox2 + // + checkBox2.AutoSize = true; + checkBox2.Location = new Point(360, 121); + checkBox2.Name = "checkBox2"; + checkBox2.Size = new Size(156, 19); + checkBox2.TabIndex = 8; + checkBox2.Text = "转换时使用源文件位置"; + checkBox2.UseVisualStyleBackColor = true; + // + // checkBox1 + // + checkBox1.AutoSize = true; + checkBox1.ForeColor = Color.Red; + checkBox1.Location = new Point(360, 96); + checkBox1.Name = "checkBox1"; + checkBox1.Size = new Size(138, 19); + checkBox1.TabIndex = 7; + checkBox1.Text = "允许覆盖文件(危险)"; + checkBox1.UseVisualStyleBackColor = true; + // + // textBox2 + // + textBox2.Location = new Point(74, 59); + textBox2.Name = "textBox2"; + textBox2.Size = new Size(362, 23); + textBox2.TabIndex = 6; + // + // button2 + // + button2.Location = new Point(442, 58); + button2.Name = "button2"; + button2.Size = new Size(52, 23); + button2.TabIndex = 5; + button2.Text = "浏览"; + button2.UseVisualStyleBackColor = true; + button2.Click += Button2_Click; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(6, 62); + label3.Name = "label3"; + label3.Size = new Size(62, 15); + label3.TabIndex = 4; + label3.Text = "目标位置:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(6, 24); + label2.Name = "label2"; + label2.Size = new Size(62, 15); + label2.TabIndex = 3; + label2.Text = "表格文件:"; + label2.TextAlign = ContentAlignment.TopCenter; + // + // textBox1 + // + textBox1.Location = new Point(74, 20); + textBox1.Name = "textBox1"; + textBox1.Size = new Size(362, 23); + textBox1.TabIndex = 2; + // + // button1 + // + button1.Location = new Point(442, 20); + button1.Name = "button1"; + button1.Size = new Size(52, 23); + button1.TabIndex = 1; + button1.Text = "浏览"; + button1.UseVisualStyleBackColor = true; + button1.Click += Button1_Click; + // // tabPage3 // tabPage3.Location = new Point(4, 24); tabPage3.Name = "tabPage3"; tabPage3.Padding = new Padding(3); - tabPage3.Size = new Size(768, 398); + tabPage3.Size = new Size(528, 396); tabPage3.TabIndex = 2; tabPage3.Text = "数据核验"; tabPage3.UseVisualStyleBackColor = true; @@ -85,7 +276,7 @@ tabPage4.Location = new Point(4, 24); tabPage4.Name = "tabPage4"; tabPage4.Padding = new Padding(3); - tabPage4.Size = new Size(768, 398); + tabPage4.Size = new Size(528, 396); tabPage4.TabIndex = 3; tabPage4.Text = "高级功能"; tabPage4.UseVisualStyleBackColor = true; @@ -95,20 +286,33 @@ tabPage5.Location = new Point(4, 24); tabPage5.Name = "tabPage5"; tabPage5.Padding = new Padding(3); - tabPage5.Size = new Size(768, 398); + tabPage5.Size = new Size(528, 396); tabPage5.TabIndex = 4; tabPage5.Text = "关于"; tabPage5.UseVisualStyleBackColor = true; // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(3, 0); + label1.Name = "label1"; + label1.Size = new Size(82, 15); + label1.TabIndex = 0; + label1.Text = "xlsx表格文件:"; + // // Form1 // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(560, 448); Controls.Add(tabControl1); Name = "Form1"; Text = "AsmrManage"; tabControl1.ResumeLayout(false); + tabPage2.ResumeLayout(false); + groupBox2.ResumeLayout(false); + groupBox1.ResumeLayout(false); + groupBox1.PerformLayout(); ResumeLayout(false); } @@ -120,5 +324,22 @@ private TabPage tabPage3; private TabPage tabPage4; private TabPage tabPage5; + private GroupBox groupBox1; + private Button button1; + private Label label1; + private TextBox textBox1; + private Label label2; + private TextBox textBox2; + private Button button2; + private Label label3; + private CheckBox checkBox2; + private CheckBox checkBox1; + private Button button3; + private CheckBox checkBox3; + private GroupBox groupBox2; + private RichTextBox logBox1; + private Label label4; + private TextBox textBox3; + private CheckBox checkBox4; } } \ No newline at end of file diff --git a/AsmrManage/AsmrManage/Form1.cs b/AsmrManage/AsmrManage/Form1.cs index 1b791ec..7e62e86 100644 --- a/AsmrManage/AsmrManage/Form1.cs +++ b/AsmrManage/AsmrManage/Form1.cs @@ -1,3 +1,6 @@ +using OfficeOpenXml; +using System.Data.SQLite; + namespace AsmrManage { public partial class Form1 : Form @@ -6,5 +9,134 @@ namespace AsmrManage { InitializeComponent(); } + + + private void Button1_Click(object sender, EventArgs e) + { + OpenFileDialog openFileDialog1 = new OpenFileDialog(); + openFileDialog1.Title = "ѡϵxlsxļ"; + openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); + openFileDialog1.Filter = "Excelļ|*.xlsx|ļ|*.*"; + if (openFileDialog1.ShowDialog() == DialogResult.OK) + { + textBox1.Text = openFileDialog1.FileName; + } + + } + + private void Button2_Click(object sender, EventArgs e) + { + FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog(); + folderBrowserDialog1.UseDescriptionForTitle = true; + folderBrowserDialog1.Description = "ѡ񱣴λ"; + if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) + { + textBox2.Text = folderBrowserDialog1.SelectedPath; + } + } + + private void Log(string message) + { + logBox1.AppendText(message + Environment.NewLine); + } + + private void Button3_Click(object sender, EventArgs e) + { + Log("ʼ"); + string excelFilePath = textBox1.Text; + string databaseLocation = textBox2.Text; + if (string.IsNullOrEmpty(excelFilePath) || string.IsNullOrEmpty(databaseLocation)) + { + Log("TextBox1 TextBox2 Ϊգ޷"); + return; + } + string databaseFileName = "asmr.db"; + string databasePath = Path.Combine(databaseLocation, databaseFileName); + Log($"Դļ:{excelFilePath}\nļ:{databasePath}"); + FileInfo fileInfo = new FileInfo(excelFilePath); + + string? password = null; + + if (checkBox4.Checked)// ļ뱣 + { + Log("ļ뱣"); + password = textBox3.Text; + } + + if (!File.Exists(databasePath)) + { + Log("ĿDBļڣ׼"); + SQLiteConnection.CreateFile(databasePath); + } + + string connectionString = $"Data Source={databasePath};Version=3;"; + + Task.Run(() => + { + try + { + using (ExcelPackage package = new ExcelPackage(fileInfo, password)) + { + using (SQLiteConnection connection = new SQLiteConnection(connectionString)) + { + connection.Open(); + + foreach (var worksheet in package.Workbook.Worksheets) + { + string tableName = worksheet.Name; + BeginInvoke((Action)(() => + { + Log($"ʼ{tableName}"); + })); + + + // һ洢 + string createTableQuery = $"CREATE TABLE IF NOT EXISTS {tableName} (asmr_id TEXT, asmr_order_id INTEGER)"; + using (SQLiteCommand command = new SQLiteCommand(createTableQuery, connection)) + { + command.ExecuteNonQuery(); + } + + int rowCount = worksheet.Dimension.Rows; + + for (int row = 2; row <= rowCount; row++) // ӵڶпʼһDZͷ + { + string? asmr_id = worksheet.Cells[row, 1].Value?.ToString(); + int asmr_order_id = Convert.ToInt32(worksheet.Cells[row, 2].Value); + + string insertDataQuery = $"INSERT INTO {tableName} (asmr_id, asmr_order_id) VALUES (@asmr_id, @asmr_order_id)"; + + using (SQLiteCommand insertCommand = new SQLiteCommand(insertDataQuery, connection)) + { + insertCommand.Parameters.AddWithValue("@asmr_id", asmr_id); + insertCommand.Parameters.AddWithValue("@asmr_order_id", asmr_order_id); + + insertCommand.ExecuteNonQuery(); + } + } + } + } + } + } + catch (Exception ex) + { + BeginInvoke((Action)(() => + { + Log($"ERROR: {ex}"); + })); + return; + } + BeginInvoke((Action)(() => + { + Log("SUCCESS"); + })); + }); + } + + private void CheckBox4_CheckedChanged(object sender, EventArgs e) + { + textBox3.ReadOnly = !checkBox4.Checked; + } + } } \ No newline at end of file diff --git a/AsmrManage/AsmrManage/Properties/Resources.Designer.cs b/AsmrManage/AsmrManage/Properties/Resources.Designer.cs new file mode 100644 index 0000000..a3480f3 --- /dev/null +++ b/AsmrManage/AsmrManage/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace AsmrManage.Properties { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AsmrManage.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 重写当前线程的 CurrentUICulture 属性,对 + /// 使用此强类型资源类的所有资源查找执行重写。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/AsmrManage/AsmrManage/Properties/Resources.resx b/AsmrManage/AsmrManage/Properties/Resources.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/AsmrManage/AsmrManage/Properties/Resources.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/AsmrManage/AsmrManage/Properties/launchSettings.json b/AsmrManage/AsmrManage/Properties/launchSettings.json new file mode 100644 index 0000000..a52672a --- /dev/null +++ b/AsmrManage/AsmrManage/Properties/launchSettings.json @@ -0,0 +1,10 @@ +{ + "profiles": { + "AsmrManage": { + "commandName": "Project", + "environmentVariables": { + "EPPlusLicenseContext": "Commercial" + } + } + } +} \ No newline at end of file