Explorar el Código

增加数据绑定

master
fyf hace 2 años
padre
commit
5c18efd087
Se han modificado 13 ficheros con 812 adiciones y 47 borrados
  1. +328
    -0
      BPASmartClient.Compiler/HttpRequestHelper.cs
  2. +5
    -1
      BPASmartClient.DATABUS/Class_DataBus.cs
  3. +18
    -0
      BPASmartClient.MessageName/EnumHelp/InterfaceModeEnum.cs
  4. +4
    -0
      BPASmartClient.SCADAControl/BPASmartClient.SCADAControl.csproj
  5. +13
    -0
      BPASmartClient.SCADAControl/CustomerControls/TheAPI.xaml
  6. +293
    -0
      BPASmartClient.SCADAControl/CustomerControls/TheAPI.xaml.cs
  7. +123
    -32
      BPASmartClient.SCADAControl/CustomerControls/TheDataGrid.xaml.cs
  8. +12
    -12
      BPASmartClient.SCADAControl/CustomerControls/TheListBox.xaml.cs
  9. +1
    -1
      BPASmartClient.SCADAControl/CustomerControls/TheTextBlock.cs
  10. BIN
     
  11. +7
    -1
      SCADA.Test/MainWindow.xaml
  12. +8
    -0
      SCADA.Test/SCADA.Test.csproj
  13. BIN
     

+ 328
- 0
BPASmartClient.Compiler/HttpRequestHelper.cs Ver fichero

@@ -0,0 +1,328 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.Compiler
{
/// <summary>
/// 该类实现客户端http 同步请求
/// 支持环境 -.net4.0/-.net4.5
/// 创建人:奉友福
/// </summary>
public class HttpRequestHelper
{
#region 私有变量
#endregion

#region 公用函数
/// <summary>
/// GET 同步请求
/// 创建人:奉友福
/// 创建时间:2020-11-19
/// </summary>
/// <param name="url">请求地址</param>
/// <returns>超时时间设置,默认5秒</returns>
public static string HttpGetRequest(string url,int _timeout = 2000)
{
string resultData = string.Empty;

try
{
WebClient wc = new WebClient();
byte[] bytes = wc.DownloadData(url);
string s = Encoding.UTF8.GetString(bytes);
return s;
}
catch (Exception e)
{
throw e;
}
return "";

try
{
var getrequest = HttpRequest.GetInstance().CreateHttpRequest(url,"GET",_timeout);
var getreponse = getrequest.GetResponse() as HttpWebResponse;
resultData = HttpRequest.GetInstance().GetHttpResponse(getreponse,"GET");
}
catch (Exception)
{
throw;
}
return resultData;
}
/// <summary>
/// POST 同步请求
/// 创建人:奉友福
/// 创建时间:2020-11-19
/// </summary>
/// <param name="url">请求地址</param>
/// <param name="PostJsonData">请求数据</param>
/// <returns></returns>
public static string HttpPostRequest(string url,string PostJsonData,int _timeout = 2000)
{
string resultData = string.Empty;
try
{
var postrequest = HttpRequest.GetInstance().CreateHttpRequest(url,"POST",_timeout,PostJsonData);
var postreponse = postrequest.GetResponse() as HttpWebResponse;
resultData = HttpRequest.GetInstance().GetHttpResponse(postreponse,"POST");
}
catch (Exception ex)
{
return ex.Message;
}
return resultData;
}

public static string HttpDeleteRequest(string url,string PostJsonData,int _timeout = 10000)
{
string resultData = string.Empty;
try
{
var deleteRequest = HttpRequest.CreateDeleteHttpRequest(url,PostJsonData,_timeout);
var deleteReponse = deleteRequest.GetResponse() as HttpWebResponse;
using (StreamReader reader = new StreamReader(deleteReponse.GetResponseStream(),Encoding.GetEncoding("UTF-8")))
{
resultData = reader.ReadToEnd();
}
}
catch (Exception ex)
{
}
return resultData;
}

/// <summary>
/// GET 同步请求
/// </summary>
/// <param name="url">地址</param>
/// <param name="head">头</param>
/// <param name="headInfo">内容</param>
/// <returns></returns>
public static string GetHttpGetResponseWithHead(string url,HttpRequestHeader head,string headInfo)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.ContentType = "application/json;charset=UTF-8";
request.Timeout = 6000;
request.Headers.Set(head,headInfo);
StreamReader sr = null;
HttpWebResponse response = null;
Stream stream = null;
try
{
response = (HttpWebResponse)request.GetResponse();
stream = response.GetResponseStream();
sr = new StreamReader(stream,Encoding.GetEncoding("utf-8"));
var resultData = sr.ReadToEnd();
return resultData;
}
catch (Exception ex)
{
Console.WriteLine(url + " 访问失败:" + ex.Message);
//return ex.Message;
}
finally
{
if (response != null)
{
response.Dispose();
}
if (stream != null)
{
stream.Dispose();
}
if (sr != null)
{
sr.Dispose();
}
}
return null;
}



/// <summary>
/// Post请求带Token
/// 2021-2-2 by dulf
/// </summary>
/// <param name="url"></param>
/// <param name="head"></param>
/// <param name="headInfo"></param>
/// <param name="postParam"></param>
/// <returns></returns>
public static string HttpPostResponseWithHead(string url,HttpRequestHeader head,string headInfo,string postParam,int Timeout = 6000)
{
string resultData = string.Empty;
try
{
var postrequest = WebRequest.Create(url) as HttpWebRequest;
postrequest.Timeout = Timeout;
postrequest.Method = "POST";
postrequest.ContentType = "application/json;charset=UTF-8";
postrequest.Headers.Set(head,headInfo);
byte[] data = Encoding.UTF8.GetBytes(postParam);
using (Stream reqStream = postrequest.GetRequestStream())
{
reqStream.Write(data,0,data.Length);
var postreponse = postrequest.GetResponse() as HttpWebResponse;
resultData = HttpRequest.GetInstance().GetHttpResponse(postreponse,"POST");
reqStream.Close();
}
return resultData;
}
catch (Exception ex)
{
Console.Write("请求<HttpPostResponseWithHead>异常:" + ex.Message);
}
return "";
}
#endregion

}
/// <summary>
/// HTTP请求类
/// </summary>
public class HttpRequest
{
#region 私有变量
/// <summary>
/// http请求超时时间设置
/// 默认值:5秒
/// </summary>
private static int Timeout = 5000;
#endregion

#region 单例模式
private static HttpRequest _HttpRequest = null;
public static HttpRequest GetInstance()
{
if (_HttpRequest == null)
{
_HttpRequest = new HttpRequest();
}
return _HttpRequest;
}
private HttpRequest()
{

}
#endregion

#region 公用函数
/// <summary>
/// 函数名称:创建http请求
/// 创建人:奉友福
/// 创建时间:2020-11-19
/// 例如GET 请求: 地址 + "GET"
/// 例如POST请求: 地址 + "POST" + JSON
/// </summary>
/// <param name="url">http请求地址</param>
/// <param name="requestType">http请求方式:GET/POST</param>
/// <param name="strjson">http请求附带数据</param>
/// <returns></returns>
public HttpWebRequest CreateHttpRequest(string url,string requestType,int _timeout = 5000,params object[] strjson)
{
HttpWebRequest request = null;
const string get = "GET";
const string post = "POST";
Timeout = _timeout;
if (string.Equals(requestType,get,StringComparison.OrdinalIgnoreCase))
{
request = CreateGetHttpRequest(url);
}
if (string.Equals(requestType,post,StringComparison.OrdinalIgnoreCase))
{
request = CreatePostHttpRequest(url,strjson[0].ToString());
}
return request;
}
/// <summary>
/// http获取数据
/// </summary>
/// <param name="response"></param>
/// <param name="requestType"></param>
/// <returns></returns>
public string GetHttpResponse(HttpWebResponse response,string requestType)
{
var resultData = string.Empty;
const string post = "POST";
string encoding = "UTF-8";
if (string.Equals(requestType,post,StringComparison.OrdinalIgnoreCase))
{
encoding = response.ContentEncoding;
if (encoding == null || encoding.Length < 1)
encoding = "UTF-8";
}
using (StreamReader reader = new StreamReader(response.GetResponseStream(),Encoding.GetEncoding(encoding)))
{
resultData = reader.ReadToEnd();
}
return resultData;
}
#endregion

#region 私有函数
/// <summary>
/// http+GET请求
/// </summary>
/// <param name="url">请求地址</param>
/// <returns>请求结果</returns>
private static HttpWebRequest CreateGetHttpRequest(string url)
{
var getrequest = WebRequest.Create(url) as HttpWebRequest;
getrequest.Method = "GET";
getrequest.Timeout = Timeout;
getrequest.ContentType = "application/json;charset=UTF-8";
getrequest.Proxy = null;
getrequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
return getrequest;
}
/// <summary>
/// http+POST请求
/// </summary>
/// <param name="url">请求地址</param>
/// <param name="postData"></param>
/// <returns>请求结果</returns>
private static HttpWebRequest CreatePostHttpRequest(string url,string postData)
{
var postrequest = WebRequest.Create(url) as HttpWebRequest;
//postrequest.KeepAlive = false;
postrequest.Timeout = Timeout;
postrequest.Method = "POST";
postrequest.ContentType = "application/json;charset=UTF-8";
//postrequest.ContentLength = postData.Length;
//postrequest.AllowWriteStreamBuffering = false;
//StreamWriter writer = new StreamWriter(postrequest.GetRequestStream(), Encoding.UTF8);
//writer.Write(postData);
//writer.Flush();
byte[] data = Encoding.UTF8.GetBytes(postData);
using (Stream reqStream = postrequest.GetRequestStream())
{
reqStream.Write(data,0,data.Length);
reqStream.Close();
}
return postrequest;
}

public static HttpWebRequest CreateDeleteHttpRequest(string url,string postJson,int _timeout = 5000)
{
var deleteRequest = WebRequest.Create(url) as HttpWebRequest;
deleteRequest.Timeout = _timeout;
deleteRequest.Method = "DELETE";
deleteRequest.ContentType = "application/json;charset=UTF-8";
byte[] data = Encoding.UTF8.GetBytes(postJson);
using (Stream reqStream = deleteRequest.GetRequestStream())
{
reqStream.Write(data,0,data.Length);
reqStream.Close();
}
return deleteRequest;
}
#endregion
}
}

+ 5
- 1
BPASmartClient.DATABUS/Class_DataBus.cs Ver fichero

@@ -28,7 +28,11 @@ namespace BPASmartClient.DATABUS
/// <summary>
/// 设备数据
/// </summary>
public ConcurrentDictionary<string, Dictionary<string,object>> Dic_DeviceData = new ConcurrentDictionary<string,Dictionary<string,object>>(); //原始目标链表
public ConcurrentDictionary<string, Dictionary<string,object>> Dic_DeviceData = new ConcurrentDictionary<string,Dictionary<string,object>>();
/// <summary>
/// API数据
/// </summary>
public ConcurrentDictionary<string,string> Dic_APIData = new ConcurrentDictionary<string,string>();
#endregion
}
}

+ 18
- 0
BPASmartClient.MessageName/EnumHelp/InterfaceModeEnum.cs Ver fichero

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.MessageName.EnumHelp
{
/// <summary>
/// 运行状态-枚举
/// </summary>
public enum InterfaceModeEnum
{
POST,
GET,
PUT
}
}

+ 4
- 0
BPASmartClient.SCADAControl/BPASmartClient.SCADAControl.csproj Ver fichero

@@ -10,6 +10,7 @@
<ItemGroup>
<None Remove="Fonts\ds-digib.ttf" />
<None Remove="Images\2609.png" />
<None Remove="Images\api.png" />
<None Remove="Images\biogebj.png" />
<None Remove="Images\bj.png" />
<None Remove="Images\btnnormal.png" />
@@ -60,6 +61,9 @@
<Resource Include="Images\2609.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Images\api.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Images\bj.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>


+ 13
- 0
BPASmartClient.SCADAControl/CustomerControls/TheAPI.xaml Ver fichero

@@ -0,0 +1,13 @@
<UserControl x:Class="BPASmartClient.SCADAControl.CustomerControls.TheAPI"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:BPASmartClient.SCADAControl.CustomerControls"
mc:Ignorable="d"
d:DesignHeight="40" d:DesignWidth="40">
<Grid>
<Image Source="/BPASmartClient.SCADAControl;component/Images/api.png" Tag="正常" Visibility="Visible"/>
<TextBlock HorizontalAlignment="Center" Tag="显示文字" VerticalAlignment="Bottom" Foreground="#FF02F9FF" Margin="0,0,0,-8">未运行</TextBlock>
</Grid>
</UserControl>

+ 293
- 0
BPASmartClient.SCADAControl/CustomerControls/TheAPI.xaml.cs Ver fichero

@@ -0,0 +1,293 @@
using BPASmart.Model;
using BPASmartClient.Compiler;
using BPASmartClient.DATABUS;
using BPASmartClient.MessageName.EnumHelp;
using BPASmartClient.SCADAControl;
using Newtonsoft.Json;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;


namespace BPASmartClient.SCADAControl.CustomerControls
{
/// <summary>
/// TheAPI.xaml 的交互逻辑
/// </summary>
public partial class TheAPI :UserControl, IExecutable, IDisposable
{
TextBlock textBlock = null;
public TheAPI()
{
InitializeComponent();
Width = 40;
Height = 40;
this.SizeChanged += TheAPI_SizeChanged; ;
}

private void TheAPI_SizeChanged(object sender,SizeChangedEventArgs e)
{
if (textBlock == null)
{
foreach (TextBlock tb in FindVisualChildren<TextBlock>(this))
{
if (tb.Tag != null)
{
if (tb.Tag.ToString() == "显示文字")
{
textBlock = tb;
}
}
}
}
}
public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
{
if (depObj != null)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(depObj,i);
if (child != null && child is T)
{
yield return (T)child;
}

foreach (T childOfChild in FindVisualChildren<T>(child))
{
yield return childOfChild;
}
}
}
}

public string ControlType => "控件";
private bool isExecuteState;
public bool IsExecuteState
{
get { return isExecuteState; }
set
{
isExecuteState = value;
if (IsExecuteState)
{
Register();
Style = null;
}
}
}

DispatcherTimer timer = new DispatcherTimer();
public void Register()
{
timer.Interval = TimeSpan.FromSeconds(TimeCount);
timer.Tick += Timer_Tick;
timer.Start();

}
private async void Timer_Tick(object sender,EventArgs e)
{
Config.GetInstance().RunJsScipt(TikcExecute);
try
{
switch (InterfaceMode)
{
case InterfaceModeEnum.POST:
if (!string.IsNullOrEmpty(DataSouceInformation))
{
Direction = 1;
FDataSouce = HttpRequestHelper.HttpPostRequest(DataSouceInformation,InterfaceParameters);
}
break;
case InterfaceModeEnum.GET:
if (!string.IsNullOrEmpty(DataSouceInformation))
{
Direction = 1;
FDataSouce = HttpRequestHelper.HttpGetRequest(DataSouceInformation);
}
break;
case InterfaceModeEnum.PUT:
if (!string.IsNullOrEmpty(DataSouceInformation))
{
Direction = 1;
//string data = HttpRequestHelper.HttpPostRequest(DataSouceInformation,InterfaceParameters);
}
break;
default:
break;
}
}
catch (Exception ex)
{
Direction = 2;
}
}

public void Start() => timer.Start();
public void Stop() => timer.Stop();

public void Dispose()
{
timer.Stop();
}

#region 属性
[Category("值设定")]
public int Direction
{
get { return (int)GetValue(DirectionProperty); }
set { SetValue(DirectionProperty,value); }
}
public static readonly DependencyProperty DirectionProperty =
DependencyProperty.Register("Direction",typeof(int),typeof(TheAPI),
new PropertyMetadata(0,new PropertyChangedCallback(OnPropertyChanged)));
private static void OnPropertyChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)
{
(d as TheAPI)?.Refresh();
}
public void Refresh()
{
if (textBlock != null)
{
if (Direction == 1)
{
textBlock.Visibility = Visibility.Visible;
textBlock.Text = "运行中";
textBlock.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#FF2077EC"));
}
else if (Direction == 2)
{
textBlock.Visibility = Visibility.Visible;
textBlock.Text = "故障";
textBlock.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#FFFF0202"));
}
else
{
textBlock.Visibility = Visibility.Visible;
textBlock.Text = "未运行";
textBlock.Foreground = new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#FF02F9FF"));
}
}
}
/// <summary>
/// 执行内容
/// </summary>
[Category("事件")]
public string TikcExecute
{
get { return (string)GetValue(TikcExecuteProperty); }
set { SetValue(TikcExecuteProperty,value); }
}
public static readonly DependencyProperty TikcExecuteProperty =
DependencyProperty.Register("TikcExecute",typeof(string),typeof(TheAPI),new PropertyMetadata(string.Empty));
#endregion

#region 数据绑定模块
public event EventHandler PropertyChange; //声明一个事件
[Category("数据绑定-数据来源")]
public int TimeCount
{
get { return (int)GetValue(TimeCountProperty); }
set { SetValue(TimeCountProperty,value); }
}
public static readonly DependencyProperty TimeCountProperty =
DependencyProperty.Register("TimeCount",typeof(int),typeof(TheAPI),new PropertyMetadata(5));
[Category("数据绑定-数据来源")]
public InterfaceModeEnum InterfaceMode
{
get { return (InterfaceModeEnum)GetValue(InterfaceModeProperty); }
set { SetValue(InterfaceModeProperty,value); }
}
public static readonly DependencyProperty InterfaceModeProperty =
DependencyProperty.Register("InterfaceMode",typeof(InterfaceModeEnum),typeof(TheAPI),new PropertyMetadata(InterfaceModeEnum.GET));
[Category("数据绑定-数据来源")]
public string InterfaceParameters
{
get { return (string)GetValue(InterfaceParametersProperty); }
set { SetValue(InterfaceParametersProperty,value); }
}
public static readonly DependencyProperty InterfaceParametersProperty =
DependencyProperty.Register("InterfaceParameters",typeof(string),typeof(TheAPI),new PropertyMetadata(string.Empty));
[Category("数据绑定-数据来源")]
public string DataSouceInformation
{
get { return (string)GetValue(DataSouceInformationProperty); }
set { SetValue(DataSouceInformationProperty,value); }
}
public static readonly DependencyProperty DataSouceInformationProperty =
DependencyProperty.Register("DataSouceInformation",typeof(string),typeof(TheAPI),new PropertyMetadata("http://localhost:9092/api/User/UsersTestSwagger"));
[Category("数据绑定-数据来源")]
public string DeviceName
{
get { return (string)GetValue(DeviceNameProperty); }
set { SetValue(DeviceNameProperty,value); }
}
public static readonly DependencyProperty DeviceNameProperty =
DependencyProperty.Register("DeviceName",typeof(string),typeof(TheAPI),new PropertyMetadata(string.Empty));
[Category("数据绑定")]
public string FDataSouce
{
get { return (string)GetValue(FDataSouceProperty); }
set { SetValue(FDataSouceProperty,value); }
}
public static readonly DependencyProperty FDataSouceProperty =
DependencyProperty.Register("FDataSouce",typeof(string),typeof(TheAPI),new PropertyMetadata(string.Empty,new PropertyChangedCallback(onFDataSouceChanged)));
private static void onFDataSouceChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) => (d as TheAPI)?.DataSouceRefresh();
public void DataSouceRefresh()
{
try
{
if (!string.IsNullOrEmpty(FDataSouce))
{
GenerateData = (string)CSharpConfig.GetInstance().RunCSharp(Code,new object[] { FDataSouce });
Class_DataBus.GetInstance().Dic_APIData[this.Name] = GenerateData;
if (PropertyChange != null)
{
PropertyChange(this,null);
}
}
}
catch (Exception ex)
{

}
}
public static string _code = "public string main(string message) \n{ \n //请在此填写你的代码\n\n return message; \n}\n";
[Category("数据绑定")]
public string Code
{
get { return (string)GetValue(CodeProperty); }
set { SetValue(CodeProperty,value); }
}
public static readonly DependencyProperty CodeProperty =
DependencyProperty.Register("Code",typeof(string),typeof(TheAPI),new PropertyMetadata(_code));
[Category("数据绑定")]
public string GenerateData
{
get { return (string)GetValue(GenerateDataProperty); }
set { SetValue(GenerateDataProperty,value); }
}
public static readonly DependencyProperty GenerateDataProperty =
DependencyProperty.Register("GenerateData",typeof(string),typeof(TheAPI),new PropertyMetadata(string.Empty));
#endregion



}
}

+ 123
- 32
BPASmartClient.SCADAControl/CustomerControls/TheDataGrid.xaml.cs Ver fichero

@@ -1,6 +1,9 @@
using BPASmartClient.Compiler;
using BPASmartClient.DATABUS;
using BPASmartClient.MessageName.EnumHelp;
using BPASmartClient.MessageName.接收消息Model.物料仓;
using BPASmartClient.SCADAControl.Converters;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -17,6 +20,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace BPASmartClient.SCADAControl.CustomerControls
{
@@ -25,42 +29,24 @@ namespace BPASmartClient.SCADAControl.CustomerControls
/// </summary>
public partial class TheDataGrid :DataGrid, IExecutable
{
public event EventHandler PropertyChange; //声明一个事件

public TheDataGrid()
{
InitializeComponent();
ResourceDictionary languageResDic = new ResourceDictionary();
languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml",UriKind.RelativeOrAbsolute);
this.Resources.MergedDictionaries.Add(languageResDic);
// Style = Application.Current.Resources["DesignTheDataGrid"] as Style;
MinWidth = 100;
MinHeight = 100;
ItemsString =new ItemsListObj()
{
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
};
}

public ItemsListObj ItemsString
public DataSouceModel ItemsString
{
get { return (ItemsListObj)GetValue(ItemsStringProperty); }
get { return (DataSouceModel)GetValue(ItemsStringProperty); }
set { SetValue(ItemsStringProperty,value); }
}

public static readonly DependencyProperty ItemsStringProperty =
DependencyProperty.Register("ItemsString",typeof(ItemsListObj),typeof(TheDataGrid),new PropertyMetadata(null));



DependencyProperty.Register("ItemsString",typeof(DataSouceModel),typeof(TheDataGrid),new PropertyMetadata(new DataSouceModel()));

public string ControlType => "控件";

@@ -78,30 +64,135 @@ namespace BPASmartClient.SCADAControl.CustomerControls
}
}
}
DispatcherTimer timer = new DispatcherTimer();
/// <summary>
/// 注册需要处理的事件
/// </summary>
public void Register()
{
// 运行时进行项目绑定
Binding binding = new Binding();
binding.RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.Self };
binding.Path = new PropertyPath("ItemsString");

timer.Interval = TimeSpan.FromMilliseconds(TimeCount);
timer.Tick += Timer_Tick; ;
timer.Start();
}

private void Timer_Tick(object? sender,EventArgs e)
{
if (!string.IsNullOrEmpty(DataSouceInformation))
{
if (Class_DataBus.GetInstance().Dic_APIData.ContainsKey(DataSouceInformation))
{
FDataSouce= Class_DataBus.GetInstance().Dic_APIData[DataSouceInformation];// = GenerateData;
}
}
}


#region 数据绑定模块
public event EventHandler PropertyChange; //声明一个事件
[Category("数据绑定-数据来源")]
public DataTypeEnum DataSouceType
{
get { return (DataTypeEnum)GetValue(DataSouceTypeProperty); }
set { SetValue(DataSouceTypeProperty,value); }
}
public static readonly DependencyProperty DataSouceTypeProperty =
DependencyProperty.Register("DataSouceType",typeof(DataTypeEnum),typeof(TheDataGrid),new PropertyMetadata(DataTypeEnum.API接口));
[Category("数据绑定-数据来源")]
public int TimeCount
{
get { return (int)GetValue(TimeCountProperty); }
set { SetValue(TimeCountProperty,value); }
}
public static readonly DependencyProperty TimeCountProperty =
DependencyProperty.Register("TimeCount",typeof(int),typeof(TheDataGrid),new PropertyMetadata(5));
[Category("数据绑定-数据来源")]
public string DataSouceInformation
{
get { return (string)GetValue(DataSouceInformationProperty); }
set { SetValue(DataSouceInformationProperty,value); }
}
public static readonly DependencyProperty DataSouceInformationProperty =
DependencyProperty.Register("DataSouceInformation",typeof(string),typeof(TheDataGrid),new PropertyMetadata(string.Empty));

SetBinding(ItemsSourceProperty,binding);

[Category("数据绑定")]
public string FDataSouce
{
get { return (string)GetValue(FDataSouceProperty); }
set { SetValue(FDataSouceProperty,value); }
}
public static readonly DependencyProperty FDataSouceProperty =
DependencyProperty.Register("FDataSouce",typeof(string),typeof(TheDataGrid),new PropertyMetadata(string.Empty,new PropertyChangedCallback(onFDataSouceChanged)));
private static void onFDataSouceChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) => (d as TheDataGrid)?.DataSouceRefresh();
public void DataSouceRefresh()
{
try
{
if (!string.IsNullOrEmpty(FDataSouce))
{
GenerateData = (string)CSharpConfig.GetInstance().RunCSharp(Code,new object[] { FDataSouce });
if (PropertyChange != null)
{
PropertyChange(this,null);
}
}
}
catch (Exception ex)
{

private void MyButton_Click(object sender,RoutedEventArgs e)
}
}
public static string _code = "public string main(string message) \n{ \n //请在此填写你的代码\n\n return message; \n}\n";
[Category("数据绑定")]
public string Code
{
get { return (string)GetValue(CodeProperty); }
set { SetValue(CodeProperty,value); }
}
public static readonly DependencyProperty CodeProperty =
DependencyProperty.Register("Code",typeof(string),typeof(TheDataGrid),new PropertyMetadata(_code));
[Category("数据绑定")]
public string GenerateData
{
get { return (string)GetValue(GenerateDataProperty); }
set { SetValue(GenerateDataProperty,value); }
}
public static readonly DependencyProperty GenerateDataProperty =
DependencyProperty.Register("GenerateData",typeof(string),typeof(TheDataGrid),new PropertyMetadata(string.Empty,new PropertyChangedCallback(onGenerateDataChanged)));
private static void onGenerateDataChanged(DependencyObject d,DependencyPropertyChangedEventArgs e) => (d as TheDataGrid)?.GenerateDataRefresh();
public void GenerateDataRefresh()
{
if (!string.IsNullOrEmpty(GenerateData) && GenerateData.Contains("data"))
{
try
{
ItemsString = JsonConvert.DeserializeObject<DataSouceModel>(GenerateData);
// 运行时进行项目绑定
Binding binding = new Binding();
binding.RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.Self };
binding.Path = new PropertyPath("ItemsString.data");
SetBinding(ItemsSourceProperty,binding);
}
catch (Exception ex)
{

}
}
}
#endregion


}

public class datalist
public class DataSouceModel
{
public string Name { get; set; }
public string Description { get; set; }
public string Messgae { get; set; }
public List<object> data {get; set; }
public DataSouceModel()
{
data = new List<object>();
}
}
}

+ 12
- 12
BPASmartClient.SCADAControl/CustomerControls/TheListBox.xaml.cs Ver fichero

@@ -36,18 +36,18 @@ namespace BPASmartClient.SCADAControl.CustomerControls
//Style = Application.Current.Resources["DesignTheListBox"] as Style;
MinWidth = 100;
MinHeight = 100;
ItemsString = new ItemsListObj()
{
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
};
//ItemsString = new ItemsListObj()
//{
// new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
// new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
// new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
// new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
// new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
// new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
// new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
// new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
// new datalist { Name="23232",Description="wwewewew",Messgae="564654645"},
//};
}

public ItemsListObj ItemsString


+ 1
- 1
BPASmartClient.SCADAControl/CustomerControls/TheTextBlock.cs Ver fichero

@@ -59,7 +59,7 @@ namespace BPASmartClient.SCADAControl.CustomerControls
set { SetValue(TimeCountProperty,value); }
}
public static readonly DependencyProperty TimeCountProperty =
DependencyProperty.Register("TimeCount",typeof(int),typeof(TheTextBlock),new PropertyMetadata(5));
DependencyProperty.Register("TimeCount",typeof(int),typeof(TheTextBlock),new PropertyMetadata(50));
public event EventHandler PropertyChange; //声明一个事件
/// <summary>
/// 属性刷新器



+ 7
- 1
SCADA.Test/MainWindow.xaml Ver fichero

@@ -8,7 +8,8 @@
xmlns:local="clr-namespace:SCADA.Test"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="200"/>
@@ -20,6 +21,11 @@
</Grid.RowDefinitions>
<Button Click="Button_Click">加载文件</Button>

<Grid Grid.Row="1" >
<Grid.Background>
<ImageBrush ImageSource="/bj.png"/>
</Grid.Background>
</Grid>
<local:RunCanvas Grid.Row="1" x:Name="runCanvas"/>

<TextBox x:Name="LogShow" Grid.Row="2" TextWrapping="Wrap" Foreground="#FFF100C7" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" FontFamily="宋体" Background="#FF282B29" FontSize="10"></TextBox>


+ 8
- 0
SCADA.Test/SCADA.Test.csproj Ver fichero

@@ -7,6 +7,10 @@
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<None Remove="bj.png" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>
@@ -19,4 +23,8 @@
<ProjectReference Include="..\BPASmartClient.SCADAControl\BPASmartClient.SCADAControl.csproj" />
</ItemGroup>

<ItemGroup>
<Resource Include="bj.png" />
</ItemGroup>

</Project>


Cargando…
Cancelar
Guardar