|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- using BPASmartClient.Compiler;
- using BPASmartClient.MessageCommunication;
- using BPASmartClient.MessageCommunication.MsgControl;
- using BPASmartClient.MessageName;
- using BPASmartClient.MessageName.EnumHelp;
- using BPASmartClient.MessageName.发送消息Model;
- using BPASmartClient.MessageName.接收消息Model;
- using BPASmartClient.MessageName.接收消息Model.物料仓;
- using Microsoft.Win32;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.IO;
- 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.Markup;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
-
- namespace SCADA.Test
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow :Window
- {
- /// <summary>
- /// 控件集合
- /// </summary>
- List<FrameworkElement> Children = new List<FrameworkElement>();
- /// <summary>
- /// 接收消息集合
- /// </summary>
- List<EventReceiveMessage> eventReceiveMessages = new List<EventReceiveMessage>();
- FRedisClient fRedisClient = new FRedisClient();
-
- public MainWindow()
- {
- InitializeComponent();
-
- fRedisClient.Connect("124.222.238.75:16000,password=123456,defaultDatabase=1");
- Dictionary<string,string> sdsd= fRedisClient.GetKeys();
- string _code = " public string main(string message) \n { \n //请在此填写你的代码\n\n return message; \n }\n";
- string GenerateData = (string)CSharpConfig.GetInstance().RunCSharp(_code,new object[] { "ERERERERE" });
-
- xxnc.ItemsSource = System.Enum.GetNames(typeof(MessageNameEnum))?.ToList();
- mlname.ItemsSource = System.Enum.GetNames(typeof(MessageNameEnum))?.ToList();
- xx.ItemsSource = System.Enum.GetNames(typeof(RunEnum))?.ToList();
-
- Class_InnerMessageBus.GetInstance().ListenMessage(this,MessageNameEnum.SendMessageName.ToString(),"MainWindowHandler");
- }
-
- public void MainWindowHandler(object sender,InnerMessageEventArgs e)
- {
- try
- {
- if (e.obj_MessageObj is EventSendMessage)//接收到运行消息
- {
- EventSendMessage mode = (EventSendMessage)e.obj_MessageObj;
- LogShowText(JsonConvert.SerializeObject(mode));
- }
- }
- catch (Exception ex)
- {
-
- }
- }
-
- #region 加载数据
- public void LogShowText(string str)
- {
- LogShow.Text += str + "\n";
- }
-
- /// <summary>
- /// 加载数据
- /// </summary>
- public void LoadingData(string path)
- {
- //加载控件
- Children.Clear();
- FileStream fs = new FileStream(path,FileMode.Open,FileAccess.Read,FileShare.ReadWrite);
- using (StreamReader sr = new StreamReader(fs,System.Text.Encoding.Unicode))
- {
- while (sr.Peek() > -1)
- {
- string str = sr.ReadLine();
- //if (!str.Contains("NewConveyorBelt"))
- {
- var ele = XamlReader.Parse(str) as FrameworkElement;
- Children.Add(ele);
- }
-
- }
- }
- if (Children.Count > 0)
- {
- eventReceiveMessages = runCanvas.Run(Children);
- }
-
- }
- #endregion
-
- private void Button_Click(object sender,RoutedEventArgs e)
- {
- OpenFileDialog ofd = new OpenFileDialog();
- ofd.Filter = "布局文件|*.lay";
- if (ofd.ShowDialog() == true)
- {
- LoadingData(ofd.FileName);
- }
-
- }
-
- private void Button_Click_1(object sender,RoutedEventArgs e)
- {
- if (string.IsNullOrEmpty(mlname.Text))
- {
- MessageBox.Show("消息名称不能为空!");
- return;
- }
- if (string.IsNullOrEmpty(xx.Text))
- {
- MessageBox.Show("命令不能为空!");
- return;
- }
- RunEnumModel runEnumModel = new RunEnumModel();
- runEnumModel.Run = ToEnumValue<RunEnum>(xx.Text);
- runEnumModel.MessageID = hm.Text;
- Class_InnerMessageBus.GetInstance().PostMessage(this,mlname.Text,runEnumModel);
- }
-
- /// <summary>
- /// 根据枚举名称获取枚举值
- /// </summary>
- public T ToEnumValue<T>(string name)
- {
- return (T)Enum.Parse(typeof(T),name);
- }
-
- private void Button_Click_2(object sender,RoutedEventArgs e)
- {
- if (string.IsNullOrEmpty(xxnc.Text))
- {
- MessageBox.Show("消息名称不能为空!");
- return;
- }
- if (string.IsNullOrEmpty(ch.Text))
- {
- MessageBox.Show("仓号不能为空!");
- return;
- }
- if (string.IsNullOrEmpty(bt.Text))
- {
- MessageBox.Show("标题不能为空!");
- return;
- }
- if (string.IsNullOrEmpty(zl.Text))
- {
- MessageBox.Show("重量不能为空!");
- return;
- }
- SilosMessageModel silosMessage = new SilosMessageModel();
- silosMessage.MessageID = ch.Text;
- silosMessage.Value = zl.Text;
- silosMessage.Title = bt.Text;
- silosMessage.Text = cgs.Text;
- Class_InnerMessageBus.GetInstance().PostMessage(this,xxnc.Text,silosMessage);
-
- }
-
-
- }
- }
|