From f435fb9e1d18733235adce1024af2e41df4a5482 Mon Sep 17 00:00:00 2001 From: fyf Date: Thu, 22 Sep 2022 16:56:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4datagrid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomerControls/TheAPI.xaml.cs | 12 ++++- .../CustomerControls/TheDataGrid.xaml.cs | 46 ++++++++++++++++--- .../CustomerControls/TheMQTT.xaml.cs | 25 +++++++++- .../CustomerControls/TheRedis.xaml.cs | 25 +++++++++- BeDesignerSCADA/Controls/CanvasPanel.cs | 25 +++++----- BeDesignerSCADA/Controls/MainCanvasPanel.xaml | 11 +++-- BeDesignerSCADA/ViewModel/MainViewModelNew.cs | 2 +- 7 files changed, 118 insertions(+), 28 deletions(-) diff --git a/BPASmartClient.SCADAControl/CustomerControls/TheAPI.xaml.cs b/BPASmartClient.SCADAControl/CustomerControls/TheAPI.xaml.cs index 03606fab..3dca1094 100644 --- a/BPASmartClient.SCADAControl/CustomerControls/TheAPI.xaml.cs +++ b/BPASmartClient.SCADAControl/CustomerControls/TheAPI.xaml.cs @@ -166,6 +166,9 @@ namespace BPASmartClient.SCADAControl.CustomerControls public void Dispose() { timer.Stop(); + Direction=0; + FDataSouce = ""; + if (IsRun) IsRun = false; } #region 属性 @@ -275,7 +278,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls { try { - if (!string.IsNullOrEmpty(FDataSouce)) + //if (!string.IsNullOrEmpty(FDataSouce)) { GenerateData = (string)CSharpConfig.GetInstance().RunCSharp(Code,new object[] { FDataSouce }); Class_DataBus.GetInstance().Dic_APIData[this.Name] = GenerateData; @@ -311,6 +314,13 @@ namespace BPASmartClient.SCADAControl.CustomerControls public void IsRunRefresh() { //测试运行 + if (IsRun) + IsExecuteState = true; + else + { + IsExecuteState = false; + Dispose(); + } } [Category("数据绑定")] public string GenerateData diff --git a/BPASmartClient.SCADAControl/CustomerControls/TheDataGrid.xaml.cs b/BPASmartClient.SCADAControl/CustomerControls/TheDataGrid.xaml.cs index d61febe5..898fb51f 100644 --- a/BPASmartClient.SCADAControl/CustomerControls/TheDataGrid.xaml.cs +++ b/BPASmartClient.SCADAControl/CustomerControls/TheDataGrid.xaml.cs @@ -28,7 +28,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls /// /// TheDataGrid.xaml 的交互逻辑 /// - public partial class TheDataGrid :DataGrid, IExecutable + public partial class TheDataGrid :DataGrid, IExecutable, IDisposable { public TheDataGrid() { @@ -36,8 +36,8 @@ namespace BPASmartClient.SCADAControl.CustomerControls //ResourceDictionary languageResDic = new ResourceDictionary(); //languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml", UriKind.RelativeOrAbsolute); //this.Resources.MergedDictionaries.Add(languageResDic); - MinWidth = 100; - MinHeight = 100; + //MinWidth = 100; + //MinHeight = 100; Width = 100; Height = 100; this.Loaded += TheDataGrid_Loaded; ; @@ -55,6 +55,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls try { TabItemsStr = JsonConvert.SerializeObject(TabItems); + GenerateDataRefresh(); } catch (Exception ex) { @@ -96,6 +97,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls } } + Style = null; if (DataSouceType == DataTypeEnum.API接口) { @@ -105,6 +107,14 @@ namespace BPASmartClient.SCADAControl.CustomerControls } } + public void Dispose() + { + timer.Stop(); + FDataSouce = ""; + if (IsRun) IsRun = false; + GenerateDataRefresh(); + } + private void Timer_Tick(object? sender,EventArgs e) { if (!string.IsNullOrEmpty(DataSouceInformation)) @@ -172,7 +182,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls { try { - if (!string.IsNullOrEmpty(FDataSouce)) + //if (!string.IsNullOrEmpty(FDataSouce)) { GenerateData = (string)CSharpConfig.GetInstance().RunCSharp(Code,new object[] { FDataSouce }); if (PropertyChange != null) @@ -196,6 +206,26 @@ namespace BPASmartClient.SCADAControl.CustomerControls public static readonly DependencyProperty CodeProperty = DependencyProperty.Register("Code",typeof(string),typeof(TheDataGrid),new PropertyMetadata(_code)); [Category("数据绑定")] + public bool IsRun + { + get { return (bool)GetValue(RunProperty); } + set { SetValue(RunProperty, value); } + } + public static readonly DependencyProperty RunProperty = + DependencyProperty.Register("IsRun", typeof(bool), typeof(TheDataGrid), new PropertyMetadata(false, new PropertyChangedCallback(onIsRunChanged))); + private static void onIsRunChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as TheDataGrid)?.IsRunRefresh(); + public void IsRunRefresh() + { + //测试运行 + if (IsRun) + IsExecuteState = true; + else + { + IsExecuteState = false; + Dispose(); + } + } + [Category("数据绑定")] public string GenerateData { get { return (string)GetValue(GenerateDataProperty); } @@ -210,7 +240,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls { try { - Dictionary keys= JsonConvert.DeserializeObject>(GenerateData); + Dictionary keys = JsonConvert.DeserializeObject>(GenerateData); List> obj2 = JsonConvert.DeserializeObject>>(keys["data"].ToString()); //ItemsString = JsonConvert.DeserializeObject(GenerateData); // 运行时进行项目绑定 @@ -219,7 +249,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls this.CanUserDeleteRows = false; this.RowHeaderWidth = 0; this.GridLinesVisibility = DataGridGridLinesVisibility.None; - //this.BorderThickness = new Thickness(0); + this.BorderThickness = new Thickness(0); this.ItemsSource = ListToDataTable(obj2).DefaultView; } catch (Exception ex) @@ -227,6 +257,10 @@ namespace BPASmartClient.SCADAControl.CustomerControls } } + else + { + this.ItemsSource = new DataTable().DefaultView; + } } diff --git a/BPASmartClient.SCADAControl/CustomerControls/TheMQTT.xaml.cs b/BPASmartClient.SCADAControl/CustomerControls/TheMQTT.xaml.cs index 8e72f96b..5131a2ef 100644 --- a/BPASmartClient.SCADAControl/CustomerControls/TheMQTT.xaml.cs +++ b/BPASmartClient.SCADAControl/CustomerControls/TheMQTT.xaml.cs @@ -185,6 +185,9 @@ namespace BPASmartClient.SCADAControl.CustomerControls public void Dispose() { timer.Stop(); + Direction = 0; + FDataSouce = ""; + if (IsRun) IsRun = false; } #region 属性 @@ -308,7 +311,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls { try { - if (!string.IsNullOrEmpty(FDataSouce)) + //if (!string.IsNullOrEmpty(FDataSouce)) { GenerateData = (string)CSharpConfig.GetInstance().RunCSharp(Code,new object[] { FDataSouce }); @@ -329,6 +332,26 @@ namespace BPASmartClient.SCADAControl.CustomerControls public static readonly DependencyProperty CodeProperty = DependencyProperty.Register("Code",typeof(string),typeof(TheMQTT),new PropertyMetadata(_code)); [Category("数据绑定")] + public bool IsRun + { + get { return (bool)GetValue(RunProperty); } + set { SetValue(RunProperty, value); } + } + public static readonly DependencyProperty RunProperty = + DependencyProperty.Register("IsRun", typeof(bool), typeof(TheMQTT), new PropertyMetadata(false, new PropertyChangedCallback(onIsRunChanged))); + private static void onIsRunChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as TheMQTT)?.IsRunRefresh(); + public void IsRunRefresh() + { + //测试运行 + if (IsRun) + IsExecuteState = true; + else + { + IsExecuteState = false; + Dispose(); + } + } + [Category("数据绑定")] public string GenerateData { get { return (string)GetValue(GenerateDataProperty); } diff --git a/BPASmartClient.SCADAControl/CustomerControls/TheRedis.xaml.cs b/BPASmartClient.SCADAControl/CustomerControls/TheRedis.xaml.cs index 566b2d08..446eab74 100644 --- a/BPASmartClient.SCADAControl/CustomerControls/TheRedis.xaml.cs +++ b/BPASmartClient.SCADAControl/CustomerControls/TheRedis.xaml.cs @@ -200,6 +200,9 @@ namespace BPASmartClient.SCADAControl.CustomerControls public void Dispose() { timer.Stop(); + Direction = 0; + FDataSouce = ""; + if (IsRun) IsRun = false; } #region 属性 @@ -301,7 +304,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls { try { - if (!string.IsNullOrEmpty(FDataSouce)) + //if (!string.IsNullOrEmpty(FDataSouce)) { GenerateData = (string)CSharpConfig.GetInstance().RunCSharp(Code,new object[] { FDataSouce }); @@ -322,6 +325,26 @@ namespace BPASmartClient.SCADAControl.CustomerControls public static readonly DependencyProperty CodeProperty = DependencyProperty.Register("Code",typeof(string),typeof(TheRedis),new PropertyMetadata(_code)); [Category("数据绑定")] + public bool IsRun + { + get { return (bool)GetValue(RunProperty); } + set { SetValue(RunProperty, value); } + } + public static readonly DependencyProperty RunProperty = + DependencyProperty.Register("IsRun", typeof(bool), typeof(TheRedis), new PropertyMetadata(false, new PropertyChangedCallback(onIsRunChanged))); + private static void onIsRunChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => (d as TheRedis)?.IsRunRefresh(); + public void IsRunRefresh() + { + //测试运行 + if (IsRun) + IsExecuteState = true; + else + { + IsExecuteState = false; + Dispose(); + } + } + [Category("数据绑定")] public string GenerateData { get { return (string)GetValue(GenerateDataProperty); } diff --git a/BeDesignerSCADA/Controls/CanvasPanel.cs b/BeDesignerSCADA/Controls/CanvasPanel.cs index 5cc7d80f..40f37ead 100644 --- a/BeDesignerSCADA/Controls/CanvasPanel.cs +++ b/BeDesignerSCADA/Controls/CanvasPanel.cs @@ -929,7 +929,7 @@ namespace BeDesignerSCADA.Controls // 排除非自定义的控件们 if (!(item is IExecutable)) continue; - + if(item is IDisposable) (item as IDisposable).Dispose(); var xml = XamlWriter.Save(item); var ele = XamlReader.Parse(xml) as FrameworkElement; elements.Add(ele); @@ -947,7 +947,10 @@ namespace BeDesignerSCADA.Controls foreach (var item in Children) { - + // 排除非自定义的控件们 + if (!(item is IExecutable)) + continue; + if (item is IDisposable) (item as IDisposable).Dispose(); var xml = XamlWriter.Save(item); sb.Append(xml + "\r\n"); } @@ -967,20 +970,16 @@ namespace BeDesignerSCADA.Controls while (sr.Peek() > -1) { string str = sr.ReadLine(); - //if (!str.Contains("NewConveyorBelt")) + try + { + var ele = XamlReader.Parse(str) as FrameworkElement; + Children.Add(ele); + } + catch (Exception ex) { - try - { - var ele = XamlReader.Parse(str) as FrameworkElement; - Children.Add(ele); - } - catch (Exception ex) - { - } - } - + } } diff --git a/BeDesignerSCADA/Controls/MainCanvasPanel.xaml b/BeDesignerSCADA/Controls/MainCanvasPanel.xaml index d0906691..41e310d6 100644 --- a/BeDesignerSCADA/Controls/MainCanvasPanel.xaml +++ b/BeDesignerSCADA/Controls/MainCanvasPanel.xaml @@ -241,8 +241,11 @@ + + + @@ -326,15 +329,13 @@ - + diff --git a/BeDesignerSCADA/ViewModel/MainViewModelNew.cs b/BeDesignerSCADA/ViewModel/MainViewModelNew.cs index 5ebe7014..d268dd9c 100644 --- a/BeDesignerSCADA/ViewModel/MainViewModelNew.cs +++ b/BeDesignerSCADA/ViewModel/MainViewModelNew.cs @@ -37,7 +37,7 @@ namespace BeDesignerSCADA.ViewModel { IsRunning = !IsRunning; }); - DevNameList = new ObservableCollection() { "qqqq", "wewew" }; + //DevNameList = new ObservableCollection() { "qqqq", "wewew" }; //DataBusModel.GetInstance().RefreshTheVariableManagerAction += RefreshTheVariableManagerActionHader; }