Compare commits

...

2 Commits

Author SHA1 Message Date
Chenx221 5eac60bd7e update 2023-10-04 22:16:51 +08:00
Chenx221 f51a5b0937 update 2023-10-04 21:44:33 +08:00
6 changed files with 612 additions and 8 deletions

View File

@ -2,10 +2,33 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<SupportedOSPlatformVersion>10.0.19041.0</SupportedOSPlatformVersion>
<StartupObject>AsmrManage.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EPPlus" Version="6.2.10" />
<PackageReference Include="System.Data.SQLite" Version="1.0.118" />
<PackageReference Include="System.IO" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@ -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,199 @@
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;
checkBox2.CheckedChanged += CheckBox2_CheckedChanged;
//
// 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 +277,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 +287,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 +325,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;
}
}

View File

@ -1,3 +1,7 @@
using OfficeOpenXml;
using System.Data.SQLite;
using System.Diagnostics;
namespace AsmrManage
{
public partial class Form1 : Form
@ -6,5 +10,167 @@ 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);
logBox1.ScrollToCaret();
}
private void Button3_Click(object sender, EventArgs e)
{
Log("开始处理");
string excelFilePath = textBox1.Text;
string? databaseLocation;
if (checkBox2.Checked)
{
databaseLocation = Path.GetDirectoryName(excelFilePath);
}
else
{
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);
}
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;";
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++) // 从第二行开始,假设第一行是表头
{
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");
}));
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)
{
textBox3.ReadOnly = !checkBox4.Checked;
}
}
}

View File

@ -0,0 +1,63 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace AsmrManage.Properties {
using System;
/// <summary>
/// 一个强类型的资源类,用于查找本地化的字符串等。
/// </summary>
// 此类是由 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() {
}
/// <summary>
/// 返回此类使用的缓存的 ResourceManager 实例。
/// </summary>
[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;
}
}
/// <summary>
/// 重写当前线程的 CurrentUICulture 属性,对
/// 使用此强类型资源类的所有资源查找执行重写。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,10 @@
{
"profiles": {
"AsmrManage": {
"commandName": "Project",
"environmentVariables": {
"EPPlusLicenseContext": "Commercial"
}
}
}
}