终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

183 rivejä
5.9 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. FRedisClient fRedisClient = new FRedisClient();
  43. public MainWindow()
  44. {
  45. InitializeComponent();
  46. fRedisClient.Connect("124.222.238.75:16000,password=123456,defaultDatabase=1");
  47. Dictionary<string,string> sdsd= fRedisClient.GetKeys();
  48. string _code = " public string main(string message) \n { \n //请在此填写你的代码\n\n return message; \n }\n";
  49. string GenerateData = (string)CSharpConfig.GetInstance().RunCSharp(_code,new object[] { "ERERERERE" });
  50. xxnc.ItemsSource = System.Enum.GetNames(typeof(MessageNameEnum))?.ToList();
  51. mlname.ItemsSource = System.Enum.GetNames(typeof(MessageNameEnum))?.ToList();
  52. xx.ItemsSource = System.Enum.GetNames(typeof(RunEnum))?.ToList();
  53. Class_InnerMessageBus.GetInstance().ListenMessage(this,MessageNameEnum.SendMessageName.ToString(),"MainWindowHandler");
  54. }
  55. public void MainWindowHandler(object sender,InnerMessageEventArgs e)
  56. {
  57. try
  58. {
  59. if (e.obj_MessageObj is EventSendMessage)//接收到运行消息
  60. {
  61. EventSendMessage mode = (EventSendMessage)e.obj_MessageObj;
  62. LogShowText(JsonConvert.SerializeObject(mode));
  63. }
  64. }
  65. catch (Exception ex)
  66. {
  67. }
  68. }
  69. #region 加载数据
  70. public void LogShowText(string str)
  71. {
  72. LogShow.Text += str + "\n";
  73. }
  74. /// <summary>
  75. /// 加载数据
  76. /// </summary>
  77. public void LoadingData(string path)
  78. {
  79. //加载控件
  80. Children.Clear();
  81. FileStream fs = new FileStream(path,FileMode.Open,FileAccess.Read,FileShare.ReadWrite);
  82. using (StreamReader sr = new StreamReader(fs,System.Text.Encoding.Unicode))
  83. {
  84. while (sr.Peek() > -1)
  85. {
  86. string str = sr.ReadLine();
  87. //if (!str.Contains("NewConveyorBelt"))
  88. {
  89. var ele = XamlReader.Parse(str) as FrameworkElement;
  90. Children.Add(ele);
  91. }
  92. }
  93. }
  94. if (Children.Count > 0)
  95. {
  96. eventReceiveMessages = runCanvas.Run(Children);
  97. }
  98. }
  99. #endregion
  100. private void Button_Click(object sender,RoutedEventArgs e)
  101. {
  102. OpenFileDialog ofd = new OpenFileDialog();
  103. ofd.Filter = "布局文件|*.lay";
  104. if (ofd.ShowDialog() == true)
  105. {
  106. LoadingData(ofd.FileName);
  107. }
  108. }
  109. private void Button_Click_1(object sender,RoutedEventArgs e)
  110. {
  111. if (string.IsNullOrEmpty(mlname.Text))
  112. {
  113. MessageBox.Show("消息名称不能为空!");
  114. return;
  115. }
  116. if (string.IsNullOrEmpty(xx.Text))
  117. {
  118. MessageBox.Show("命令不能为空!");
  119. return;
  120. }
  121. RunEnumModel runEnumModel = new RunEnumModel();
  122. runEnumModel.Run = ToEnumValue<RunEnum>(xx.Text);
  123. runEnumModel.MessageID = hm.Text;
  124. Class_InnerMessageBus.GetInstance().PostMessage(this,mlname.Text,runEnumModel);
  125. }
  126. /// <summary>
  127. /// 根据枚举名称获取枚举值
  128. /// </summary>
  129. public T ToEnumValue<T>(string name)
  130. {
  131. return (T)Enum.Parse(typeof(T),name);
  132. }
  133. private void Button_Click_2(object sender,RoutedEventArgs e)
  134. {
  135. if (string.IsNullOrEmpty(xxnc.Text))
  136. {
  137. MessageBox.Show("消息名称不能为空!");
  138. return;
  139. }
  140. if (string.IsNullOrEmpty(ch.Text))
  141. {
  142. MessageBox.Show("仓号不能为空!");
  143. return;
  144. }
  145. if (string.IsNullOrEmpty(bt.Text))
  146. {
  147. MessageBox.Show("标题不能为空!");
  148. return;
  149. }
  150. if (string.IsNullOrEmpty(zl.Text))
  151. {
  152. MessageBox.Show("重量不能为空!");
  153. return;
  154. }
  155. SilosMessageModel silosMessage = new SilosMessageModel();
  156. silosMessage.MessageID = ch.Text;
  157. silosMessage.Value = zl.Text;
  158. silosMessage.Title = bt.Text;
  159. silosMessage.Text = cgs.Text;
  160. Class_InnerMessageBus.GetInstance().PostMessage(this,xxnc.Text,silosMessage);
  161. }
  162. }
  163. }