diff --git a/AuthorizeDll.zip b/AuthorizeDll.zip new file mode 100644 index 0000000..4dd9d1f Binary files /dev/null and b/AuthorizeDll.zip differ diff --git a/AuthorizeDll/App.config b/AuthorizeDll/App.config new file mode 100644 index 0000000..46d8015 --- /dev/null +++ b/AuthorizeDll/App.config @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AuthorizeDll/AuthorizeDll.zip b/AuthorizeDll/AuthorizeDll.zip new file mode 100644 index 0000000..96f6930 Binary files /dev/null and b/AuthorizeDll/AuthorizeDll.zip differ diff --git a/AuthorizeDll/CNAS.db b/AuthorizeDll/CNAS.db new file mode 100644 index 0000000..e8e2659 Binary files /dev/null and b/AuthorizeDll/CNAS.db differ diff --git a/AuthorizeDll/CNAS_Authorize.application b/AuthorizeDll/CNAS_Authorize.application new file mode 100644 index 0000000..1fcf145 --- /dev/null +++ b/AuthorizeDll/CNAS_Authorize.application @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + L5xNjTgh0dTkAQRbTZCFp78DqTJkq1K4UQdhB+a8xaQ= + + + + \ No newline at end of file diff --git a/AuthorizeDll/CNAS_Authorize.exe b/AuthorizeDll/CNAS_Authorize.exe new file mode 100644 index 0000000..21d3160 Binary files /dev/null and b/AuthorizeDll/CNAS_Authorize.exe differ diff --git a/AuthorizeDll/CNAS_Authorize.exe.config b/AuthorizeDll/CNAS_Authorize.exe.config new file mode 100644 index 0000000..46d8015 --- /dev/null +++ b/AuthorizeDll/CNAS_Authorize.exe.config @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/AuthorizeDll/CNAS_Authorize.exe.manifest b/AuthorizeDll/CNAS_Authorize.exe.manifest new file mode 100644 index 0000000..d51888c --- /dev/null +++ b/AuthorizeDll/CNAS_Authorize.exe.manifest @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + I4IqDuMxBr51Z6oX2d/YkvprGq44LkHsOXT43OvA0b8= + + + + + + + + + + + + X6xanpuLva1s9mHb8xh+OVkUzXE540tyWQbvu2ASLA0= + + + + + + + + + + qmdIROPHgqvrcwUwlaxoJeAzUhkInxx6DrCrZKLyuFE= + + + \ No newline at end of file diff --git a/AuthorizeDll/System.Data.SQLite.dll b/AuthorizeDll/System.Data.SQLite.dll new file mode 100644 index 0000000..b3fe46e Binary files /dev/null and b/AuthorizeDll/System.Data.SQLite.dll differ diff --git a/AuthorizeDll/app.publish/CNAS_Authorize.exe b/AuthorizeDll/app.publish/CNAS_Authorize.exe new file mode 100644 index 0000000..0499dbf Binary files /dev/null and b/AuthorizeDll/app.publish/CNAS_Authorize.exe differ diff --git a/CNAS_Authorize/App.config b/CNAS_Authorize/App.config index d5e2677..46d8015 100644 --- a/CNAS_Authorize/App.config +++ b/CNAS_Authorize/App.config @@ -1,13 +1,14 @@  - - - - - - - - + + + + + + + + + @@ -32,4 +33,16 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/CNAS_Authorize/CNAS_Authorize.csproj b/CNAS_Authorize/CNAS_Authorize.csproj index a2d86bc..1148b7f 100644 --- a/CNAS_Authorize/CNAS_Authorize.csproj +++ b/CNAS_Authorize/CNAS_Authorize.csproj @@ -3,7 +3,7 @@ Debug - AnyCPU + x86 {9B4A6989-A7A6-41C0-ADFE-D470EB972D79} WinExe Properties @@ -14,13 +14,29 @@ {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 true + false + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 2 + 1.0.0.%2a + false + true + true - AnyCPU + x86 true full false - ..\dll\ + ..\AuthorizeDll\ DEBUG;TRACE prompt 4 @@ -34,9 +50,23 @@ prompt 4 + + D4700213673D28F8D81D62BAEC309A35964BA214 + + + CNAS_Authorize_TemporaryKey.pfx + + + true + + + true + + + @@ -99,25 +129,21 @@ - - {8E0E5F2E-2BA2-4952-9F31-34C072CD86B3} - CnasSynchronousCommon - - - {CB9B6D92-3CC4-46C6-92E8-A6FD0AD48041} - CnasSynchronusBLL - - - {0C3243F5-729E-409C-B406-C6DE56E632E0} - CnasSynchrousModel - + + False + Microsoft .NET Framework 4.8 %28x86 和 x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + + true + - \ No newline at end of file diff --git a/CNAS_Authorize/MachineAuth.cs b/CNAS_Authorize/MachineAuth.cs index 8bd8bbb..c031ab0 100644 --- a/CNAS_Authorize/MachineAuth.cs +++ b/CNAS_Authorize/MachineAuth.cs @@ -1,12 +1,11 @@ -using CnasSynchronusClient; -using CnasSynchrousModel; -using System; +using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; +using System.Data.SQLite; namespace CNAS_Authorize { @@ -69,31 +68,43 @@ namespace CNAS_Authorize m_pageSize = 10; m_pageIndex = 1; } - DataBaseInfo targetDataBase = new DataBaseInfo(); public void Load() { - //加载CNAS数据库配置 - targetDataBase = FileOperation.GetLocalCnasDB(); - if (!CnasDataOperationFact.CnasDataOperation().TestConnect(targetDataBase)) - { - MessageBox.Show("CNAS数据库无法正常连接...", "提示"); - return; - } - - + InitializeDatabase(); + m_machines = new List(); - ////1.加载数据 - DataTable dtmacaddressinfo = CnasDataOperationFact.CnasDataOperation().GetTableData(targetDataBase, "select * from macaddress"); - if (dtmacaddressinfo != null && dtmacaddressinfo.Rows.Count > 0) + + string dbPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CNAS.db"); + string connectionString = $"Data Source={dbPath};Version=3;"; + + try { - List lstCnasTables = new List(); - foreach (DataRow dr in dtmacaddressinfo.Rows) + using (var connection = new SQLiteConnection(connectionString)) { - Machine m = new Machine( dr["PLANTCODE"].ToString(), dr["MAC_ADDRESS"].ToString(), dr["CREATETIME"].ToString(), true); - m_machines.Add(m); - lstCnasTables.Add(dr["MAC_ADDRESS"].ToString()); + connection.Open(); + using (var command = new SQLiteCommand(connection)) + { + command.CommandText = "SELECT PLANTCODE, MAC_ADDRESS, CREATETIME FROM macaddress"; + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + Machine m = new Machine( + reader["PLANTCODE"].ToString(), + reader["MAC_ADDRESS"].ToString(), + reader["CREATETIME"].ToString(), + true + ); + m_machines.Add(m); + } + } + } } } + catch (Exception ex) + { + MessageBox.Show($"加载数据失败: {ex.Message}", "错误"); + } m_rangle = new List(); m_rangle.AddRange(m_machines); @@ -103,7 +114,6 @@ namespace CNAS_Authorize m_pageCount = (m_rangle.Count / m_pageSize) + (m_rangle.Count % m_pageSize == 0 ? 0 : 1); m_page = getPageData(m_pageIndex); - } public int PageSize @@ -238,6 +248,64 @@ namespace CNAS_Authorize } + private void InitializeDatabase() + { + try + { + string dbPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CNAS.db"); + string connectionString = $"Data Source={dbPath};Version=3;"; + + // 确保数据库目录存在 + string dbDirectory = System.IO.Path.GetDirectoryName(dbPath); + if (!System.IO.Directory.Exists(dbDirectory)) + { + System.IO.Directory.CreateDirectory(dbDirectory); + } + + using (var connection = new SQLiteConnection(connectionString)) + { + connection.Open(); + using (var command = new SQLiteCommand(connection)) + { + command.CommandText = @" + CREATE TABLE IF NOT EXISTS macaddress ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + MAC_ADDRESS TEXT, + PLANTCODE TEXT, + CREATETIME TEXT, + FACILITY_STYLE TEXT + );"; + command.ExecuteNonQuery(); + } + } + } + catch (Exception ex) + { + MessageBox.Show($"初始化数据库失败: {ex.Message}", "错误"); + } + } + + private void InsertTestData() + { + string connectionString = "Data Source=|DataDirectory|\\CNAS.db;Version=3;"; + using (var connection = new SQLiteConnection(connectionString)) + { + connection.Open(); + using (var command = new SQLiteCommand(connection)) + { + command.CommandText = @" + INSERT INTO macaddress (MAC_ADDRESS, PLANTCODE, CREATETIME, FACILITY_STYLE) + VALUES (@mac, @plant, @time, @style)"; + + command.Parameters.AddWithValue("@mac", "00:11:22:33:44:55"); + command.Parameters.AddWithValue("@plant", "PLANT001"); + command.Parameters.AddWithValue("@time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + command.Parameters.AddWithValue("@style", "Style A"); + + command.ExecuteNonQuery(); + } + } + } } } diff --git a/CNAS_Authorize/MainWindow.xaml.cs b/CNAS_Authorize/MainWindow.xaml.cs index 5744375..03e9879 100644 --- a/CNAS_Authorize/MainWindow.xaml.cs +++ b/CNAS_Authorize/MainWindow.xaml.cs @@ -1,5 +1,4 @@ -using CnasSynchronousCommon; -using CnasSynchronusClient; + using System; using System.Collections.Generic; using System.Data; @@ -16,6 +15,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using System.Data.SQLite; namespace CNAS_Authorize { @@ -106,35 +106,69 @@ namespace CNAS_Authorize private void ConfirmImport_Click(object sender, RoutedEventArgs e) { - - //加载CNAS数据库配置 - var targetDataBase = FileOperation.GetLocalCnasDB(); - if (!CnasDataOperationFact.CnasDataOperation().TestConnect(targetDataBase)) + string macAddress = edtMachine.Text.Trim(); + string plantCode = edtFactory.Text.Trim(); + + if (string.IsNullOrEmpty(macAddress) || string.IsNullOrEmpty(plantCode)) { - MessageBox.Show("CNAS数据库无法正常连接...", "提示"); + MessageBox.Show("MAC地址和工厂代码不能为空!", "提示"); return; } - var existData = CnasDataOperationFact.CnasDataOperation().GetTableData(targetDataBase, $"select * from macaddress where MAC_ADDRESS='{edtMachine.Text.Trim()}'"); - if(existData!=null&& existData.Rows.Count > 0) + string connectionString = "Data Source=|DataDirectory|\\CNAS.db;Version=3;"; + using (var connection = new SQLiteConnection(connectionString)) { - MessageBox.Show("已经导入!"); - return; - } - StringBuilder sb = new StringBuilder(); - sb.AppendFormat($"insert into macaddress(MAC_ADDRESS,PLANTCODE,CREATETIME,FACILITY_STYLE) VALUES('{edtMachine.Text.Trim()}','{edtFactory.Text.Trim()}',now(),'999')"); + try + { + connection.Open(); + + // 检查是否已存在 + using (var checkCommand = new SQLiteCommand(connection)) + { + checkCommand.CommandText = "SELECT COUNT(*) FROM macaddress WHERE MAC_ADDRESS = @mac"; + checkCommand.Parameters.AddWithValue("@mac", macAddress); + + int count = Convert.ToInt32(checkCommand.ExecuteScalar()); + if (count > 0) + { + MessageBox.Show("已经导入!", "提示"); + return; + } + } - //1.加载数据 - var flag = CnasDataOperationFact.CnasDataOperation().InsertTableData(targetDataBase, sb.ToString()); - if (flag) - { - AppLog.ServiceInfo("导入成功"); - MessageBox.Show("导入成功...", "提示"); - this.LoadData(); - } - else - { - MessageBox.Show("导入失败...", "提示"); + // 插入新记录 + using (var insertCommand = new SQLiteCommand(connection)) + { + insertCommand.CommandText = @" + INSERT INTO macaddress ( + MAC_ADDRESS, + PLANTCODE, + CREATETIME, + FACILITY_STYLE + ) VALUES ( + @mac, + @plant, + @time, + @style + )"; + + insertCommand.Parameters.AddWithValue("@mac", macAddress); + insertCommand.Parameters.AddWithValue("@plant", plantCode); + insertCommand.Parameters.AddWithValue("@time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + insertCommand.Parameters.AddWithValue("@style", "999"); + + insertCommand.ExecuteNonQuery(); + + //AppLog.ServiceInfo("导入成功"); + MessageBox.Show("导入成功...", "提示"); + this.LoadData(); + } + } + catch (Exception ex) + { + MessageBox.Show($"导入失败: {ex.Message}", "提示"); + //AppLog.ServiceError($"导入失败: {ex.Message}"); + } } } diff --git a/WF-ChangeGUID/App.config b/WF-ChangeGUID/App.config index 61aa1f2..9a2a785 100644 --- a/WF-ChangeGUID/App.config +++ b/WF-ChangeGUID/App.config @@ -3,8 +3,11 @@ + - + + + @@ -29,4 +32,16 @@ - + + + + + + + + + + + + + \ No newline at end of file diff --git a/WF-ChangeGUID/WF-ChangeGUID.csproj b/WF-ChangeGUID/WF-ChangeGUID.csproj index 4f87587..392eb2a 100644 --- a/WF-ChangeGUID/WF-ChangeGUID.csproj +++ b/WF-ChangeGUID/WF-ChangeGUID.csproj @@ -36,7 +36,9 @@ + + diff --git a/create_table.sql b/create_table.sql new file mode 100644 index 0000000..5d5cb12 --- /dev/null +++ b/create_table.sql @@ -0,0 +1,7 @@ +CREATE TABLE IF NOT EXISTS macaddress ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + MAC_ADDRESS TEXT, + PLANTCODE TEXT, + CREATETIME TEXT, + FACILITY_STYLE TEXT +); \ No newline at end of file diff --git a/dll/App.config b/dll/App.config index d5e2677..46d8015 100644 --- a/dll/App.config +++ b/dll/App.config @@ -1,13 +1,14 @@  - - - - - - - - + + + + + + + + + @@ -32,4 +33,16 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/dll/CNAS.db b/dll/CNAS.db new file mode 100644 index 0000000..ea52788 Binary files /dev/null and b/dll/CNAS.db differ diff --git a/dll/CNAS_Authorize.application b/dll/CNAS_Authorize.application new file mode 100644 index 0000000..4def71d --- /dev/null +++ b/dll/CNAS_Authorize.application @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + cKvo+SG3kukqmQ2mBgqRv3fEL6oAg8Zg9rpcw+OtH8Q= + + + + \ No newline at end of file diff --git a/dll/CNAS_Authorize.exe b/dll/CNAS_Authorize.exe index a462807..4923f3a 100644 Binary files a/dll/CNAS_Authorize.exe and b/dll/CNAS_Authorize.exe differ diff --git a/dll/CNAS_Authorize.exe.config b/dll/CNAS_Authorize.exe.config index d5e2677..46d8015 100644 --- a/dll/CNAS_Authorize.exe.config +++ b/dll/CNAS_Authorize.exe.config @@ -1,13 +1,14 @@  - - - - - - - - + + + + + + + + + @@ -32,4 +33,16 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/dll/CNAS_Authorize.exe.manifest b/dll/CNAS_Authorize.exe.manifest new file mode 100644 index 0000000..87f5cf2 --- /dev/null +++ b/dll/CNAS_Authorize.exe.manifest @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + xG66i3py1dV/xiSubMXegK/WeFJrYo9kBmZXXdhFrHg= + + + + + + + + + + + + X6xanpuLva1s9mHb8xh+OVkUzXE540tyWQbvu2ASLA0= + + + + + + + + + + qmdIROPHgqvrcwUwlaxoJeAzUhkInxx6DrCrZKLyuFE= + + + \ No newline at end of file diff --git a/dll/System.Data.SQLite.dll b/dll/System.Data.SQLite.dll index a70e447..b3fe46e 100644 Binary files a/dll/System.Data.SQLite.dll and b/dll/System.Data.SQLite.dll differ diff --git a/dll/WF-ChangeGUID.exe.config b/dll/WF-ChangeGUID.exe.config index 61aa1f2..9a2a785 100644 --- a/dll/WF-ChangeGUID.exe.config +++ b/dll/WF-ChangeGUID.exe.config @@ -3,8 +3,11 @@ + - + + + @@ -29,4 +32,16 @@ - + + + + + + + + + + + + + \ No newline at end of file diff --git a/dll/app.publish/CNAS_Authorize.exe b/dll/app.publish/CNAS_Authorize.exe new file mode 100644 index 0000000..a58da49 Binary files /dev/null and b/dll/app.publish/CNAS_Authorize.exe differ