diff --git a/.idea/.idea.detect/.idea/avalonia.xml b/.idea/.idea.detect/.idea/avalonia.xml index a515ade..a74366f 100644 --- a/.idea/.idea.detect/.idea/avalonia.xml +++ b/.idea/.idea.detect/.idea/avalonia.xml @@ -12,6 +12,7 @@ + diff --git a/detect.gui/Services/DeviceClientService.cs b/detect.gui/Services/DeviceClientService.cs index bea6c7a..b9ac512 100644 --- a/detect.gui/Services/DeviceClientService.cs +++ b/detect.gui/Services/DeviceClientService.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using detect.device; -using detect.gui.Commons; using detect.gui.Models.Entities; using detect.gui.Services.Detect; using Serilog; @@ -143,8 +142,8 @@ public class DeviceClientService Log.Information("DeviceEvent-[{Name}]-{Address}:{@Result}", e.Name, (sender as DeviceClientSocket)!.Address, e.Result); if (e.Name == detect.device.DeviceEvent.EventDeviceConnected) { - var sysInfo = GetDeviceInfo(1).GetAwaiter().GetResult(); - Log.Information("device info: {@Info}", sysInfo); + // var sysInfo = GetDeviceInfo(1).GetAwaiter().GetResult(); + // Log.Information("device info: {@Info}", sysInfo); // test // AssignTasks(new long[] { 1 }).GetAwaiter(); } diff --git a/detect.gui/Views/WebBrowserWindow.axaml.cs b/detect.gui/Views/WebBrowserWindow.axaml.cs index 871ceca..de73e1b 100644 --- a/detect.gui/Views/WebBrowserWindow.axaml.cs +++ b/detect.gui/Views/WebBrowserWindow.axaml.cs @@ -1,5 +1,4 @@ -using System; -using Avalonia.Controls; +using Avalonia.Controls; using Avalonia.Markup.Xaml; using Avalonia.Platform; using detect.gui.Services; @@ -24,13 +23,14 @@ public partial class WebBrowserWindow : Window ExtendClientAreaChromeHints = ExtendClientAreaChromeHints.NoChrome; ExtendClientAreaTitleBarHeightHint = -1; SystemDecorations = SystemDecorations.None; - ShowInTaskbar = false; - Topmost = true; + // ShowInTaskbar = false; + // Topmost = true; CanResize = false; var webview = this.Get("WebView"); var service = Locator.Current.GetService(); webview.RegisterJavascriptObject("DeviceClientService", service); + webview.RegisterJavascriptObject("WebViewService", new WebViewService(this)); Log.Information("WebView Initialized."); } diff --git a/detect.gui/Views/WebViewService.cs b/detect.gui/Views/WebViewService.cs new file mode 100644 index 0000000..4b35ab4 --- /dev/null +++ b/detect.gui/Views/WebViewService.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.Encodings.Web; +using System.Text.Json; +using System.Text.Unicode; +using System.Threading.Tasks; +using Avalonia.Controls; +using OfficeOpenXml; + +namespace detect.gui.Views; + +public class WebViewService(Window? w) +{ + public Window? Self { get; set; } = w; + + [Obsolete("过时的")] + public async Task ImportExcel() + { + var dialog = new OpenFileDialog + { + Title = "打开文件", + AllowMultiple = false, + Filters = + [ + new FileDialogFilter { Name = "Excel Files", Extensions = { "*.xls; *.xlsx" } } + ] + }; + var result = await dialog.ShowAsync(Self!); + if (result is not { Length: 1 }) return null; + try + { + var ccc = ConvertExcelToJson(result[0]); + return ConvertExcelToJson(result[0]); + } + catch (Exception e) + { + return null; + } + } + + public static string ConvertExcelToJson(string excelFilePath) + { + ExcelPackage.LicenseContext = LicenseContext.NonCommercial; + var fileInfo = new FileInfo(excelFilePath); + using var package = new ExcelPackage(fileInfo); + var worksheet = package.Workbook.Worksheets[0]; + var rowCount = worksheet.Dimension.Rows; + var colCount = worksheet.Dimension.Columns; + + var data = new List>(); + var headers = Enumerable.Range(1, colCount) + .Select(col => worksheet.Cells[1, col].Text) + .ToList(); + for (var row = 2; row <= rowCount; row++) + { + var rowData = new Dictionary(); + for (var col = 1; col <= colCount; col++) + { + rowData[headers[col - 1]] = worksheet.Cells[row, col].Text; + } + + data.Add(rowData); + } + return JsonSerializer.Serialize(data, new JsonSerializerOptions { WriteIndented = true, Encoder = JavaScriptEncoder.Create(UnicodeRanges.All) }); + } +} \ No newline at end of file diff --git a/detect.gui/detect.gui.csproj b/detect.gui/detect.gui.csproj index 9e3f273..59c4f2c 100644 --- a/detect.gui/detect.gui.csproj +++ b/detect.gui/detect.gui.csproj @@ -31,6 +31,7 @@ + diff --git a/detect.sln.DotSettings.user b/detect.sln.DotSettings.user index 21f0d43..c482172 100644 --- a/detect.sln.DotSettings.user +++ b/detect.sln.DotSettings.user @@ -4,6 +4,9 @@ ForceIncluded ForceIncluded ForceIncluded + ForceIncluded + ForceIncluded + ForceIncluded ForceIncluded ForceIncluded ForceIncluded