From 9211ec11c112e18cd99e77f889a01110a70031ce Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期一, 24 十一月 2025 17:47:15 +0800
Subject: [PATCH] 优化项目结构

---
 HMI.DataViewer/DataViewer.xaml.cs |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/HMI.DataViewer/DataViewer.xaml.cs b/HMI.DataViewer/DataViewer.xaml.cs
index e6dafc7..cd1a970 100644
--- a/HMI.DataViewer/DataViewer.xaml.cs
+++ b/HMI.DataViewer/DataViewer.xaml.cs
@@ -176,7 +176,7 @@
             Map.Clear();
             foreach (var data in settings)
             {
-                Map.Add(data.Program, data);
+                Map[data.Program] = data;
                 names.Add(data.Program);
             }
             programInput.ItemsSource = names;
@@ -304,14 +304,19 @@
 
         private DataTable DoSearchData(DataBase_Setting setting, List<QueryData> datas)
         {
+            string conditon = "WHERE 1=1 ";
             string fields = string.Join(",", Datas?.Select(d => $"[{d.Key}]").ToList());
+            if (datas != null && datas.Count > 0)
+            {
+                conditon = "WHERE " + string.Join(" AND ", datas.Select(d => $"[{d.Key}] {d.Condition} '{d.Value}'").ToList());
+            }
 
-            string conditon = string.Join(" AND ", datas.Select(d => $"[{d.Key}] {d.Condition} '{d.Value}'").ToList());
             string timeCol = setting.TimeCol;
             if (string.IsNullOrEmpty(timeCol))
             {
                 timeCol = "time";
             }
+
             if (!string.IsNullOrEmpty(startTimeInput.Text))
             {
                 conditon += $" AND {timeCol} >= '{startTimeInput.Text}'";
@@ -320,7 +325,6 @@
             {
                 conditon += $" AND {timeCol} < '{endTimeInput.Text}'";
             }
-            conditon = string.IsNullOrEmpty(conditon) ? string.Empty : $" WHERE {conditon}";
 
             SqliteHelper helper = null;
             string sql = string.Empty;
@@ -354,7 +358,9 @@
             }
 
             var datas = Datas?.Where(d => !string.IsNullOrEmpty(d.Value)).ToList();
-            if (datas == null || datas.Count <= 0)
+
+            if ((datas == null || datas.Count <= 0) &&
+                (string.IsNullOrEmpty(startTimeInput.Text) || string.IsNullOrEmpty(endTimeInput.Text)))
             {
                 ToastHelper.Warning(Window.GetWindow(this), this.lang("Dv.QueryCantBeEmpty"));
                 return;
@@ -431,7 +437,7 @@
                 workbook.CreateSheet("sheet1");////鏂板缓涓�涓伐浣滆〃
                 XSSFSheet SheetOne = (XSSFSheet)workbook.GetSheet("Sheet1"); ////鑾峰彇鍚嶇О涓篠heet1鐨勫伐浣滆〃,鍒涘缓鏍囬澶�
                 IRow row1 = SheetOne.CreateRow(0);////鑾峰彇Sheet1宸ヤ綔琛ㄧ殑棣栬,璁剧疆琛ㄥご锛岃幏鍙栧垪
-                XSSFCell[] SheetCell = new XSSFCell[currentColumns.Count];
+                //XSSFCell[] SheetCell = new XSSFCell[currentColumns.Count];
                 for (int i = 0; i < currentColumns.Count; i++)
                 {
                     row1.CreateCell(i).SetCellValue(currentColumns[i].Header.ToString());

--
Gitblit v1.9.1