终端一体化运控平台
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

182 linhas
5.7 KiB

  1. using BPASmartClient.Compiler;
  2. using BPASmartClient.MessageCommunication;
  3. using BPASmartClient.MessageCommunication.MsgControl;
  4. using BPASmartClient.MessageName;
  5. using BPASmartClient.MessageName.EnumHelp;
  6. using BPASmartClient.MessageName.发送消息Model;
  7. using BPASmartClient.MessageName.接收消息Model;
  8. using BPASmartClient.MessageName.接收消息Model.物料仓;
  9. using Microsoft.Win32;
  10. using Newtonsoft.Json;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Data;
  20. using System.Windows.Documents;
  21. using System.Windows.Input;
  22. using System.Windows.Markup;
  23. using System.Windows.Media;
  24. using System.Windows.Media.Imaging;
  25. using System.Windows.Navigation;
  26. using System.Windows.Shapes;
  27. namespace SCADA.Test
  28. {
  29. /// <summary>
  30. /// Interaction logic for MainWindow.xaml
  31. /// </summary>
  32. public partial class MainWindow :Window
  33. {
  34. /// <summary>
  35. /// 控件集合
  36. /// </summary>
  37. List<FrameworkElement> Children = new List<FrameworkElement>();
  38. /// <summary>
  39. /// 接收消息集合
  40. /// </summary>
  41. List<EventReceiveMessage> eventReceiveMessages = new List<EventReceiveMessage>();
  42. public MainWindow()
  43. {
  44. InitializeComponent();
  45. RedisHelper.GetInstance.ConnectAsync(String.Empty);
  46. string _code = " public string main(string message) \n { \n //请在此填写你的代码\n\n return message; \n }\n";
  47. string GenerateData = (string)CSharpConfig.GetInstance().RunCSharp(_code,new object[] { "ERERERERE" });
  48. xxnc.ItemsSource = System.Enum.GetNames(typeof(MessageNameEnum))?.ToList();
  49. mlname.ItemsSource = System.Enum.GetNames(typeof(MessageNameEnum))?.ToList();
  50. xx.ItemsSource = System.Enum.GetNames(typeof(RunEnum))?.ToList();
  51. Class_InnerMessageBus.GetInstance().ListenMessage(this,MessageNameEnum.SendMessageName.ToString(),"MainWindowHandler");
  52. }
  53. public void MainWindowHandler(object sender,InnerMessageEventArgs e)
  54. {
  55. try
  56. {
  57. if (e.obj_MessageObj is EventSendMessage)//接收到运行消息
  58. {
  59. EventSendMessage mode = (EventSendMessage)e.obj_MessageObj;
  60. LogShowText(JsonConvert.SerializeObject(mode));
  61. }
  62. }
  63. catch (Exception ex)
  64. {
  65. }
  66. }
  67. #region 加载数据
  68. public void LogShowText(string str)
  69. {
  70. LogShow.Text += str + "\n";
  71. }
  72. /// <summary>
  73. /// 加载数据
  74. /// </summary>
  75. public void LoadingData(string path)
  76. {
  77. //加载控件
  78. Children.Clear();
  79. FileStream fs = new FileStream(path,FileMode.Open,FileAccess.Read,FileShare.ReadWrite);
  80. using (StreamReader sr = new StreamReader(fs,System.Text.Encoding.Unicode))
  81. {
  82. while (sr.Peek() > -1)
  83. {
  84. string str = sr.ReadLine();
  85. //if (!str.Contains("NewConveyorBelt"))
  86. {
  87. var ele = XamlReader.Parse(str) as FrameworkElement;
  88. Children.Add(ele);
  89. }
  90. }
  91. }
  92. if (Children.Count > 0)
  93. {
  94. eventReceiveMessages = runCanvas.Run(Children);
  95. }
  96. }
  97. #endregion
  98. private void Button_Click(object sender,RoutedEventArgs e)
  99. {
  100. OpenFileDialog ofd = new OpenFileDialog();
  101. ofd.Filter = "布局文件|*.lay";
  102. if (ofd.ShowDialog() == true)
  103. {
  104. LoadingData(ofd.FileName);
  105. }
  106. }
  107. private void Button_Click_1(object sender,RoutedEventArgs e)
  108. {
  109. if (string.IsNullOrEmpty(mlname.Text))
  110. {
  111. MessageBox.Show("消息名称不能为空!");
  112. return;
  113. }
  114. if (string.IsNullOrEmpty(xx.Text))
  115. {
  116. MessageBox.Show("命令不能为空!");
  117. return;
  118. }
  119. RunEnumModel runEnumModel = new RunEnumModel();
  120. runEnumModel.Run = ToEnumValue<RunEnum>(xx.Text);
  121. runEnumModel.MessageID = hm.Text;
  122. Class_InnerMessageBus.GetInstance().PostMessage(this,mlname.Text,runEnumModel);
  123. }
  124. /// <summary>
  125. /// 根据枚举名称获取枚举值
  126. /// </summary>
  127. public T ToEnumValue<T>(string name)
  128. {
  129. return (T)Enum.Parse(typeof(T),name);
  130. }
  131. private void Button_Click_2(object sender,RoutedEventArgs e)
  132. {
  133. if (string.IsNullOrEmpty(xxnc.Text))
  134. {
  135. MessageBox.Show("消息名称不能为空!");
  136. return;
  137. }
  138. if (string.IsNullOrEmpty(ch.Text))
  139. {
  140. MessageBox.Show("仓号不能为空!");
  141. return;
  142. }
  143. if (string.IsNullOrEmpty(bt.Text))
  144. {
  145. MessageBox.Show("标题不能为空!");
  146. return;
  147. }
  148. if (string.IsNullOrEmpty(zl.Text))
  149. {
  150. MessageBox.Show("重量不能为空!");
  151. return;
  152. }
  153. SilosMessageModel silosMessage = new SilosMessageModel();
  154. silosMessage.MessageID = ch.Text;
  155. silosMessage.Value = zl.Text;
  156. silosMessage.Title = bt.Text;
  157. silosMessage.Text = cgs.Text;
  158. Class_InnerMessageBus.GetInstance().PostMessage(this,xxnc.Text,silosMessage);
  159. }
  160. }
  161. }