From b544d5cccd76735e034c8055918a50927b437474 Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期二, 10 十一月 2026 08:29:04 +0800
Subject: [PATCH] fix: 维护模式重复进入失败与按钮灰死 + Broker 并发验证用例

---
 Plugin.DataBoard/DataBoard.xaml.cs |  594 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 546 insertions(+), 48 deletions(-)

diff --git a/Plugin.DataBoard/DataBoard.xaml.cs b/Plugin.DataBoard/DataBoard.xaml.cs
index 7e66211..538e8c7 100644
--- a/Plugin.DataBoard/DataBoard.xaml.cs
+++ b/Plugin.DataBoard/DataBoard.xaml.cs
@@ -1,13 +1,27 @@
 锘縰sing HMI.Base;
+using HMI.Core.Entity;
+using HMI.Core.Manager;
+using HMI.Core.Setting;
 using HMI.Core.Util;
 using HMI.UI.Util;
 using HMI.Util;
+using LiveChartsCore;
+using LiveChartsCore.Drawing;
+using LiveChartsCore.Drawing.Layouts;
+using LiveChartsCore.Kernel.Sketches;
+using LiveChartsCore.SkiaSharpView;
+using LiveChartsCore.SkiaSharpView.Drawing;
+using LiveChartsCore.SkiaSharpView.Drawing.Geometries;
+using LiveChartsCore.SkiaSharpView.Drawing.Layouts;
+using LiveChartsCore.SkiaSharpView.Painting;
+using LiveChartsCore.SkiaSharpView.SKCharts;
+using LiveChartsCore.SkiaSharpView.VisualElements;
 using Microsoft.Web.WebView2.Core;
+using SkiaSharp;
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Data;
-using System.Drawing;
 using System.IO;
 using System.Linq;
 using System.Threading.Tasks;
@@ -16,6 +30,54 @@
 
 namespace Plugin.DataBoard
 {
+    public class CustomLegend : SKDefaultLegend
+    {
+
+        protected override Layout<SkiaSharpDrawingContext> GetLayout(LiveChartsCore.Chart chart)
+        {
+            var stackLayout = new StackLayout
+            {
+                Orientation = ContainerOrientation.Horizontal,
+                Padding = new Padding(0, 10, 0, 0),
+                HorizontalAlignment = Align.Start,
+                VerticalAlignment = Align.Middle,
+            };
+
+            foreach (var series in chart.Series.Where(x => x.IsVisibleAtLegend))
+            {
+                stackLayout.Children.Add(new LegendItem(series));
+            }
+            return stackLayout;
+        }
+    }
+
+    public class LegendItem : StackLayout
+    {
+        public LegendItem(ISeries series)
+        {
+            Orientation = ContainerOrientation.Horizontal;
+            Padding = new Padding(0);
+            VerticalAlignment = Align.Start;
+            HorizontalAlignment = Align.Middle;
+            Opacity = series.IsVisible ? 1 : 0.5f;
+
+            var miniature = (IDrawnElement<SkiaSharpDrawingContext>)series.GetMiniatureGeometry(null);
+            Children = new List<IDrawnElement<SkiaSharpDrawingContext>> {
+                miniature,
+            new LabelGeometry
+            {
+                Text = series.Name,
+                TextSize = 12,
+                Paint = new SolidColorPaint(SKColors.Black){
+                    SKTypeface = SKFontManager.Default.MatchCharacter('姹�')
+                },
+                Padding = new Padding(5,0,10,0),
+                VerticalAlign = Align.Middle,
+                HorizontalAlign = Align.Start
+            }};
+        }
+    }
+
     /// <summary>
     /// UserControl1.xaml 鐨勪氦浜掗�昏緫
     /// </summary>
@@ -25,8 +87,308 @@
         {
             DataContext = this;
             InitializeComponent();
-            webview2.DefaultBackgroundColor = Color.Transparent;//Color.FromArgb(243, 249, 255);
+            //webview2.DefaultBackgroundColor = Color.Transparent;//Color.FromArgb(243, 249, 255);
         }
+
+        private SolidColorPaint tooltipTextPaint = new SolidColorPaint(SKColors.Black)
+        {
+            SKTypeface = SKFontManager.Default.MatchCharacter('姹�')
+        };
+        public SolidColorPaint TooltipTextPaint
+        {
+            get => tooltipTextPaint;
+            set
+            {
+                Set(ref tooltipTextPaint, value);
+            }
+        }
+        #region chart0
+
+        public LabelVisual Chart0Title { get; set; } = new LabelVisual
+       {
+           Text = "鎶曞叆浜у嚭缁熻",
+           TextSize = 20,
+           Paint = new SolidColorPaint(new SKColor(0, 0, 0))
+           {
+               SKTypeface = SKFontManager.Default.MatchCharacter('姹�')
+           },
+           Padding = new LiveChartsCore.Drawing.Padding(15)
+       };
+
+        private ISeries[] chart0_series = new ISeries[] {
+            new ColumnSeries<int> { 
+                Fill= new SolidColorPaint(new SKColor(34, 68, 139)),
+                DataLabelsPaint  = new SolidColorPaint(new SKColor(0, 0, 0)),
+                DataLabelsPosition = LiveChartsCore.Measure.DataLabelsPosition.Top,
+                Values = new int[]{ 0,0} }
+        };
+
+        public ISeries[] Chart0_series
+        {
+            get => chart0_series;
+            set
+            {
+                Set(ref chart0_series, value);
+            }
+        }
+
+        private ObservableCollection<Axis> chart0_yAxes = new ObservableCollection<Axis> {
+            new Axis
+            {
+                MinStep = 1,
+                MinLimit = 0,
+                LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)),
+                SeparatorsPaint = new SolidColorPaint
+                {
+                    Color = SKColors.Black.WithAlpha(30),
+                    StrokeThickness = 0.5f
+                },
+                TicksPaint = new SolidColorPaint
+                {
+                    Color = SKColor.Empty,
+                    StrokeThickness = 0
+                },
+            }
+        };
+
+        public ObservableCollection<Axis> Chart0_yAxes
+        {
+            get => chart0_yAxes;
+            set
+            {
+                Set(ref chart0_yAxes, value);
+            }
+        }
+
+        private Axis[] chart0_xAxes = new Axis[] {
+            new Axis
+        {
+            Labels = new string[]{"鎶曞叆", "浜у嚭" },
+            LabelsPaint=new SolidColorPaint(new SKColor(0, 0, 0))
+            {
+                SKTypeface = SKFontManager.Default.MatchCharacter('姹�')
+            },
+            LabelsRotation = 0,
+            SeparatorsAtCenter = false,
+            TicksPaint = new SolidColorPaint(new SKColor(35, 35, 35)),
+            TicksAtCenter = true,
+            ForceStepToMin = true,
+            MinStep = 1
+        }
+        };
+        public Axis[] Chart0_xAxes
+        {
+            get => chart0_xAxes;
+            set
+            {
+                Set(ref chart0_xAxes, value);
+            }
+        }
+        #endregion
+
+        #region chart1
+
+        public LabelVisual Chart1Title { get; set; } = new LabelVisual
+        {
+            Text = "浜у搧鐘舵�佺粺璁�",
+            TextSize = 20,
+            Paint = new SolidColorPaint(new SKColor(0, 0, 0))
+            {
+                SKTypeface = SKFontManager.Default.MatchCharacter('姹�')
+            },
+            Padding = new LiveChartsCore.Drawing.Padding(15)
+        };
+
+        public ISeries[] Chart1_series { get; set; } = new PieSeries<int>[]
+        {
+            new PieSeries<int> {
+                Name="Passed",
+                Values = new int[]{ 0},
+            DataLabelsPosition = LiveChartsCore.Measure.PolarLabelsPosition.Outer,
+             DataLabelsSize = 15,
+             DataLabelsPaint = new SolidColorPaint(new SKColor(30, 30, 30)){
+                 SKTypeface = SKFontManager.Default.MatchCharacter('姹�')
+             },
+             Fill = new SolidColorPaint(new SKColor(0, 128, 0)),
+             DataLabelsFormatter =
+                point =>point.StackedValue.Total>0?
+                    $"Passed\r\n璁℃暟:{point.Coordinate.PrimaryValue}\r\n鍗犳瘮:{point.StackedValue.Share:P2}":"",
+             ToolTipLabelFormatter = point => $"{point.StackedValue.Share:P2}"
+            },
+            new PieSeries<int> { Values = new int[]{ 0} ,
+                Name="Failed",
+            DataLabelsPosition = LiveChartsCore.Measure.PolarLabelsPosition.Outer,
+             DataLabelsSize = 15,
+             DataLabelsPaint = new SolidColorPaint(new SKColor(30, 30, 30)){
+                 SKTypeface = SKFontManager.Default.MatchCharacter('姹�')
+             },
+             Fill = new SolidColorPaint(new SKColor(255, 0, 0)),
+             DataLabelsFormatter =
+                point =>point.StackedValue.Total>0?
+                    $"Failed\r\n璁℃暟:{point.Coordinate.PrimaryValue}\r\n鍗犳瘮:{point.StackedValue.Share:P2}":"",
+             ToolTipLabelFormatter = point => $"{point.StackedValue.Share:P2}"},
+        };
+
+        #endregion
+
+        #region chart2
+
+        public LabelVisual Chart2Title { get; set; } = new LabelVisual
+        {
+            Text = "鑹巼缁熻",
+            TextSize = 20,
+            Paint = new SolidColorPaint(new SKColor(0, 0, 0))
+            {
+                SKTypeface = SKFontManager.Default.MatchCharacter('姹�')
+            },
+            Padding = new LiveChartsCore.Drawing.Padding(15)
+        };
+
+        public ISeries[] Chart2_series { get; set; } = new ISeries[]
+        {
+            new LineSeries<double> {
+                Name="鐩撮�氱巼",
+                Values = new double[]{ 0},
+                DataLabelsPosition = LiveChartsCore.Measure.DataLabelsPosition.Top,
+                DataLabelsFormatter =
+                    point => $"鐩撮�氱巼:{point.Coordinate.PrimaryValue:f2}%",
+                DataLabelsSize = 15,
+                DataLabelsPaint = new SolidColorPaint(new SKColor(30, 30, 30)){
+                    SKTypeface = SKFontManager.Default.MatchCharacter('姹�')
+                },
+                Stroke = new SolidColorPaint(new SKColor(255,0,0)){
+                    StrokeThickness = 2
+                },
+                Fill = null,
+                GeometryStroke = new SolidColorPaint(new SKColor(255,0,0)){
+                    StrokeThickness = 2
+                },
+                GeometrySize=5
+            },
+            new LineSeries<double> {
+                Name="鑹巼",
+                Values = new double[]{ 0},
+            DataLabelsPosition = LiveChartsCore.Measure.DataLabelsPosition.Bottom,
+            DataLabelsFormatter =
+                point => $"鑹巼:{point.Coordinate.PrimaryValue:f2}%",
+             DataLabelsSize = 10,
+             DataLabelsPaint = new SolidColorPaint(new SKColor(30, 30, 30)){
+                 SKTypeface = SKFontManager.Default.MatchCharacter('姹�')
+             },
+                Stroke = new SolidColorPaint(new SKColor(34, 68, 139)){
+                    StrokeThickness = 2
+                },
+                GeometryStroke = new SolidColorPaint(new SKColor(34, 68, 139)){
+                    StrokeThickness = 2
+                },
+             Fill = null,
+            },
+        };
+
+        private ObservableCollection<Axis> chart2_yAxes = new ObservableCollection<Axis>  {
+            new Axis
+            {
+                LabelsPaint = new SolidColorPaint(new SKColor(0, 0, 0)),
+                SeparatorsPaint = new SolidColorPaint
+                {
+                    Color = SKColors.Black.WithAlpha(30),
+                    StrokeThickness = 0.5f
+                },
+                TicksPaint = new SolidColorPaint
+                {
+                    Color = SKColor.Empty,
+                    StrokeThickness = 0
+                },
+                MinLimit = 0
+            }
+        };
+        public ObservableCollection<Axis> Chart2_yAxes
+        {
+            get => chart2_yAxes;
+            set
+            {
+                Set(ref chart2_yAxes, value);
+            }
+        }
+
+        private ObservableCollection<ICartesianAxis> chart2_xAxes = new ObservableCollection<ICartesianAxis> {
+            new Axis
+            {
+            Labels = new string[]{"" },
+            }
+        };
+
+        public ObservableCollection<ICartesianAxis> Chart2_xAxes {
+            get => chart2_xAxes;
+            set {
+                Set(ref chart2_xAxes, value);
+            }
+        }
+
+        #endregion
+
+        #region chart3
+
+        public LabelVisual Chart3Title { get; set; } = new LabelVisual
+        {
+            Text = "TOP10涓嶈壇缁熻",
+            TextSize = 20,
+            Paint = new SolidColorPaint(new SKColor(0, 0, 0))
+            {
+                SKTypeface = SKFontManager.Default.MatchCharacter('姹�')
+            },
+            Padding = new LiveChartsCore.Drawing.Padding(15)
+        };
+
+        public ISeries[] Chart3_series { get; set; } = new ISeries[]
+        {
+            new RowSeries<SimpleData> {
+                Values = new SimpleData[]{},
+                DataLabelsPosition = LiveChartsCore.Measure.DataLabelsPosition.Left,
+                DataLabelsFormatter =
+                    point => $"{point.Model.Name}",
+
+                DataLabelsSize = 15,
+                DataLabelsPadding = new Padding(30,0,0,0),
+                DataLabelsTranslate = new LvcPoint(1, 0),
+                // DataLabelsTranslate = new LvcPoint(-1, 0),
+                DataLabelsPaint = new SolidColorPaint(new SKColor(255,0,0)){
+                    SKTypeface = SKFontManager.Default.MatchCharacter('姹�')
+                },
+                YToolTipLabelFormatter = point => $"{point.Model.Name} {point.Model.Value}"
+            },
+        };
+
+        public ObservableCollection<Axis> chart3_yAxes = new ObservableCollection<Axis>  {
+            new Axis
+            {
+                IsVisible = false
+            }
+        };
+        public ObservableCollection<Axis> Chart3_yAxes
+        {
+            get => chart3_yAxes;
+            set
+            {
+                Set(ref chart3_yAxes, value);
+            }
+        }
+
+        private ObservableCollection<ICartesianAxis> chart3_xAxes = new ObservableCollection<ICartesianAxis> {
+            new Axis { SeparatorsPaint = new SolidColorPaint(new SKColor(220, 220, 220)) }
+        };
+
+        public ObservableCollection<ICartesianAxis> Chart3_xAxes
+        {
+            get => chart3_xAxes;
+            set
+            {
+                Set(ref chart3_xAxes, value);
+            }
+        }
+
+        #endregion
+
 
         private ObservableCollection<OptionData> _options = new ObservableCollection<OptionData> {
             new OptionData { Name = LangUtil.Get("bd.today"), Value = "today" },
@@ -41,9 +403,85 @@
             set { Set(ref _options, value); }
         }
 
+
+        private string iniFile;
+        private string DataFolder;
+        public override void InitFinish()
+        {
+            chart2.Legend = new CustomLegend();
+            iniFile = Path.Combine(BaseFolder, "Config.ini");
+            if (!File.Exists(iniFile))
+            {
+                File.Create(iniFile);
+            }
+            DataFolder = ParamSetting.DataLogFolder;
+            LoadProduct();
+        }
+
         private void PluginControl_Loaded(object sender, RoutedEventArgs e)
         {
+            cb0.SelectedIndex = 0;
+            cb1.SelectedIndex = 0;
+            cb2.SelectedIndex = 0;
+            cb3.SelectedIndex = 0;
+        }
 
+        private void LoadProduct()
+        {
+            List<ProductData> products = ProductManager.GetProducts<List<ProductData>>()
+               ?? new List<ProductData>();
+            this.modelSelect.Items.Clear();
+            List<string> productSource = new List<string>();
+            foreach (var prd in products)
+            {
+                this.modelSelect.Items.Add(prd.Name);
+                productSource.Add(prd.Name);
+            }
+
+            string model = IniFileHelper.ReadIniData("Config", "Model", "", iniFile);
+            if (!string.IsNullOrEmpty(model))
+            {
+                this.modelSelect.SelectedItem = model;
+            }
+            else if (products.Count > 0)
+            {
+                this.modelSelect.SelectedIndex = 0;
+            }
+        }
+
+        private void RefreshAll()
+        {
+            try
+            {
+                var start0 = dtp00.SelectedDateTime ?? DateTime.Now;
+                var end0 = dtp01.SelectedDateTime ?? DateTime.Now;
+                RefreshChart0(start0, end0);
+            }
+            catch { }
+
+            try
+            {
+                var start1 = dtp10.SelectedDateTime ?? DateTime.Now;
+                var end1 = dtp11.SelectedDateTime ?? DateTime.Now;
+                RefreshChart1(start1, end1);
+            }
+            catch { }
+
+            try
+            {
+                var start2 = dtp20.SelectedDateTime ?? DateTime.Now;
+                var end2 = dtp21.SelectedDateTime ?? DateTime.Now;
+                RefreshChart2(start2, end2);
+            }
+            catch { }
+
+            try
+            {
+                var start3 = dtp30.SelectedDateTime ?? DateTime.Now;
+                var end3 = dtp31.SelectedDateTime ?? DateTime.Now;
+                RefreshChart3(start3, end3);
+            }
+            catch { }
         }
 
         private void Button_Click(object sender, RoutedEventArgs e)
@@ -52,6 +490,9 @@
             DateTime start, end;
             switch (btn.Name)
             {
+                case "btnAll":
+                    RefreshAll();
+                    break;
                 case "btn0":
                     start = dtp00.SelectedDateTime ?? DateTime.Now;
                     end = dtp01.SelectedDateTime ?? DateTime.Now;
@@ -77,15 +518,15 @@
             }
         }
 
-        public static string[] GetDbFiles(string folderPath, DateTime startTime, DateTime endTime)
+        public string[] GetDbFiles(DateTime startTime, DateTime endTime)
         {
-            if (!Directory.Exists(folderPath))
+            if (!Directory.Exists(DataFolder))
             {
                 return new string[0];
             }
             string startName = $"Data_{startTime.ToString("yyyyMMdd")}";
             string endName = $"Data_{endTime.ToString("yyyyMMdd")}";
-            var oldFiles = Directory.GetFiles(folderPath, "Data_*.db");
+            var oldFiles = Directory.GetFiles(DataFolder, "Data_*.db");
             oldFiles = oldFiles.Where(file =>
             {
                 var fileName = Path.GetFileNameWithoutExtension(file);
@@ -99,15 +540,22 @@
         }
 
 
-        private List<SerialData> SelectSerialDataByTime(DateTime start, DateTime end)
+        private List<SerialData> SelectSerialDataByTime(string model, DateTime start, DateTime end)
         {
             var s1 = DateTime.Now;
-            string[] files = GetDbFiles(BaseFolder, start, end);
+            string[] files = GetDbFiles(start, end);
             if (files == null || files.Length <= 0)
             {
                 return new List<SerialData>();
             }
-            string sql = $"SELECT * FROM serialData WHERE time BETWEEN '{start:yyyy-MM-dd HH:mm:ss}' AND '{end:yyyy-MM-dd HH:mm:ss}' ORDER BY time DESC;";
+            string segment = string.Empty;
+            if (!string.IsNullOrEmpty(model))
+            {
+                segment = $"AND model = '{model}'";
+            }
+
+            string sql = $@"SELECT * FROM serialData WHERE time BETWEEN '{start:yyyy-MM-dd HH:mm:ss}' AND '{end:yyyy-MM-dd HH:mm:ss}' 
+{segment} ORDER BY time DESC;";
 
             DataTable dt = new DataTable();
             foreach (string file in files)
@@ -124,14 +572,21 @@
             return data;
         }
 
-        private List<SerialData> SelectResultDataByTime(DateTime start, DateTime end)
+        private List<SerialData> SelectResultDataByTime(string model, DateTime start, DateTime end)
         {
-            string[] files = GetDbFiles(BaseFolder, start, end);
+            string[] files = GetDbFiles(start, end);
             if (files == null || files.Length <= 0)
             {
                 return new List<SerialData>();
             }
-            string sql = $"SELECT * FROM testResult WHERE time BETWEEN '{start:yyyy-MM-dd HH:mm:ss}' AND '{end:yyyy-MM-dd HH:mm:ss}';";
+
+            string segment = string.Empty;
+            if (!string.IsNullOrEmpty(model))
+            {
+                segment = $"AND model = '{model}'";
+            }
+
+            string sql = $@"SELECT * FROM testResult WHERE time BETWEEN '{start:yyyy-MM-dd HH:mm:ss}' AND '{end:yyyy-MM-dd HH:mm:ss}' {segment} Order BY id DESC;";
 
             DataTable dt = new DataTable();
             foreach (string file in files)
@@ -148,22 +603,23 @@
         private void webview2_Loaded(object sender, RoutedEventArgs e)
         {
             string path = Path.Combine(PathHelper.AppFolder, "Libs", "Static", "test.html");
-            webview2.Source = new Uri(path);
+            //webview2.EnsureCoreWebView2Async();
+            // webview2.Source = new Uri(path);           
         }
 
         private void Webview2_NavigationCompleted(object sender, CoreWebView2NavigationCompletedEventArgs e)
         {
-            cb0.SelectedIndex = 0;
-            cb1.SelectedIndex = 0;
-            cb2.SelectedIndex = 0;
-            cb3.SelectedIndex = 0;
+            //cb0.SelectedIndex = 0;
+            //cb1.SelectedIndex = 0;
+            //cb2.SelectedIndex = 0;
+            //cb3.SelectedIndex = 0;
         }
 
         private void webview2_SizeChanged(object sender, SizeChangedEventArgs e)
         {
-            var width = this.webview2.ActualWidth - 100;
-            var height = this.webview2.ActualHeight;
-            webview2.CoreWebView2?.ExecuteScriptAsync($"resize({width},{height})");
+            //var width = this.webview2.ActualWidth - 100;
+            //var height = this.webview2.ActualHeight;
+            //webview2.CoreWebView2?.ExecuteScriptAsync($"resize({width},{height})");
         }
 
         //private void RefreshChart0(DateTime start, DateTime end)
@@ -206,15 +662,16 @@
         {
             dtp00.SelectedDateTime = start;
             dtp01.SelectedDateTime = end;
+            string model = modelSelect.SelectedItem?.ToString();
             Task.Run(() =>
             {
                 try
                 {
                     Dispatcher.BeginInvoke(new Action(() =>
                     {
-                        webview2.CoreWebView2?.ExecuteScriptAsync($"loading0('鍔犺浇涓紝璇风◢鍚�...')");
+                        // webview2.CoreWebView2?.ExecuteScriptAsync($"loading0('鍔犺浇涓紝璇风◢鍚�...')");
                     }));
-                    List<SerialData> datas = SelectResultDataByTime(start, end);
+                    List<SerialData> datas = SelectResultDataByTime(model, start, end);
                     datas.OrderByDescending(e => e.time);
                     int all = 0, output = 0;
                     HashSet<string> snCache = new HashSet<string>();
@@ -228,7 +685,8 @@
                     var fields = $"['{this.lang("bd.input")}','{this.lang("bd.output")}']";
                     Dispatcher.BeginInvoke(new Action(() =>
                     {
-                        webview2.CoreWebView2?.ExecuteScriptAsync($"drawChart0({fields}, [{all},{output}])");
+                        Chart0_series[0].Values = new int[] { all, output };
+                        //webview2.CoreWebView2?.ExecuteScriptAsync($"drawChart0({fields}, [{all},{output}])");
                     }));
                 }
                 catch (Exception ex)
@@ -243,18 +701,19 @@
         {
             dtp10.SelectedDateTime = start;
             dtp11.SelectedDateTime = end;
+            string model = modelSelect.SelectedItem?.ToString();
             Task.Run(() =>
             {
                 try
                 {
                     Dispatcher.BeginInvoke(new Action(() =>
                     {
-                        webview2.CoreWebView2?.ExecuteScriptAsync($"loading1('鍔犺浇涓紝璇风◢鍚�...')");
+                        //webview2.CoreWebView2?.ExecuteScriptAsync($"loading1('鍔犺浇涓紝璇风◢鍚�...')");
                     }));
-                    List<SerialData> datas = SelectResultDataByTime(start, end);
+                    List<SerialData> datas = SelectResultDataByTime(model, start, end);
 
                     datas = datas.OrderByDescending(e => e.time).ToList();
-                    Dictionary<string, int?> pieData = new Dictionary<string, int?> {
+                    Dictionary<string, int> pieData = new Dictionary<string, int> {
                 { "Passed",0},
                 { "Failed",0},
                 //{ "Action",0},
@@ -286,7 +745,9 @@
                     res += "]";
                     Dispatcher.BeginInvoke(new Action(() =>
                     {
-                        webview2.CoreWebView2?.ExecuteScriptAsync($"drawChart1({res})");
+                        Chart1_series[0].Values = new int[] { pieData["Passed"] };
+                        Chart1_series[1].Values = new int[] { pieData["Failed"] };
+                        // webview2.CoreWebView2?.ExecuteScriptAsync($"drawChart1({res})");
                     }));
                 }
                 catch (Exception ex)
@@ -367,15 +828,16 @@
         {
             dtp20.SelectedDateTime = start;
             dtp21.SelectedDateTime = end;
+            string model = modelSelect.SelectedItem?.ToString();
             Task.Run(() =>
             {
                 try
                 {
                     Dispatcher.BeginInvoke(new Action(() =>
                     {
-                        webview2.CoreWebView2?.ExecuteScriptAsync($"loading2('鍔犺浇涓紝璇风◢鍚�...')");
+                       // webview2.CoreWebView2?.ExecuteScriptAsync($"loading2('鍔犺浇涓紝璇风◢鍚�...')");
                     }));
-                    List<SerialData> datas = SelectResultDataByTime(start, end);
+                    List<SerialData> datas = SelectResultDataByTime(model, start, end);
 
                     var groups =
                         datas.GroupBy(d => d.time.ToString("yyyy-MM-dd"));
@@ -418,20 +880,46 @@
                         });
                     }
 
-                    string fields = "[", vals0 = "[", vals1 = "[";
-                    foreach (var key in res.Keys)
-                    {
-                        fields += $"'{key}',";
-                        vals0 += $"{res[key].onePassRate},";
-                        vals1 += $"{res[key].passRate},";
-                    }
-                    fields += "]";
-                    vals0 += "]";
-                    vals1 += "]";
+                    //string fields = "[", vals0 = "[", vals1 = "[";
+                    //foreach (var key in res.Keys)
+                    //{
+                    //    fields += $"'{key}',";
+                    //    vals0 += $"{res[key].onePassRate},";
+                    //    vals1 += $"{res[key].passRate},";
+                    //}
+                    //fields += "]";
+                    //vals0 += "]";
+                    //vals1 += "]";
                     var names = $"['{this.lang("bd.onePassRate")}','{this.lang("bd.passRate")}']";
                     Dispatcher.BeginInvoke(new Action(() =>
                     {
-                        webview2.CoreWebView2?.ExecuteScriptAsync($"drawChart2({fields},{names},{vals0},{vals1})");
+                        if (res.Count == 0)
+                        {
+                            res[DateTime.Now.ToString("yyyy-MM-dd")] = new PassRateData
+                            {
+                                onePassRate = 0,
+                                passRate = 0
+                            };
+                        }
+
+                        string[] keys = new string[res.Count];
+                        double[] val0 = new double[res.Count];
+                        double[] val1 = new double[res.Count];
+                        int i = 0;
+                        foreach (var key in res.Keys)
+                        {
+                            keys[i] = key;
+                            val0[i] = res[key].onePassRate;
+                            val1[i] = res[key].passRate;
+                            i++;
+                        }
+                        Chart2_xAxes[0] = new Axis
+                        {
+                            Labels = keys,
+                        };
+                        Chart2_series[0].Values = val0;
+                        Chart2_series[1].Values = val1;
+                        //webview2.CoreWebView2?.ExecuteScriptAsync($"drawChart2({fields},{names},{vals0},{vals1})");
                     }));
                 }
                 catch (Exception ex)
@@ -446,16 +934,17 @@
         {
             dtp30.SelectedDateTime = start;
             dtp31.SelectedDateTime = end;
+            string model = modelSelect.SelectedItem?.ToString();
             Task.Run(() =>
             {
                 try
                 {
                     Dispatcher.BeginInvoke(new Action(() =>
                     {
-                        webview2.CoreWebView2?.ExecuteScriptAsync($"loading3('鍔犺浇涓紝璇风◢鍚�...')");
+                        //webview2.CoreWebView2?.ExecuteScriptAsync($"loading3('鍔犺浇涓紝璇风◢鍚�...')");
                     }));
                     var st = DateTime.Now;
-                    List<SerialData> datas = SelectSerialDataByTime(start, end);
+                    List<SerialData> datas = SelectSerialDataByTime(model, start, end);
                     var s2 = DateTime.Now;
                     log.Info($"RefreshChart3 Data Cast {(s2 - st).TotalMilliseconds}");
 
@@ -489,15 +978,16 @@
                     var s3 = DateTime.Now;
                     log.Info($"RefreshChart3 Build {(s3 - s2).TotalMilliseconds}");
 
-                    string names = string.Empty, vals = string.Empty;
-                    foreach (var data in datasource)
-                    {
-                        names += $"'{data.Name}',";
-                        vals += $"{data.Value},";
-                    }
+                    //string names = string.Empty, vals = string.Empty;
+                    //foreach (var data in datasource)
+                    //{
+                    //    names += $"'{data.Name}',";
+                    //    vals += $"{data.Value},";
+                    //}
                     Dispatcher.BeginInvoke(new Action(() =>
                     {
-                        webview2.CoreWebView2?.ExecuteScriptAsync($"drawChart3([{names}],[{vals}])");
+                        Chart3_series[0].Values = datasource.OrderBy(x => x.Value).ToList(); ;
+                        //webview2.CoreWebView2?.ExecuteScriptAsync($"drawChart3([{names}],[{vals}])");
                     }));
                 }
                 catch (Exception ex)
@@ -544,5 +1034,13 @@
                     break;
             }
         }
+
+        private void modelSelect_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            if (e.AddedItems.Count > 0)
+            {
+                IniFileHelper.WriteIniData("Config", "Model", e.AddedItems[0].ToString(), iniFile);
+            }
+        }
     }
 }

--
Gitblit v1.9.1