终端一体化运控平台
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.
 
 
 

138 lines
4.2 KiB

  1. using BPASmartClient.MessageCommunication;
  2. using BPASmartClient.MessageName;
  3. using BPASmartClient.MessageName.Enum.物料仓;
  4. using BPASmartClient.MessageName.Enum.运行状态;
  5. using Microsoft.Win32;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Data;
  15. using System.Windows.Documents;
  16. using System.Windows.Input;
  17. using System.Windows.Markup;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. using System.Windows.Navigation;
  21. using System.Windows.Shapes;
  22. namespace SCADA.Test
  23. {
  24. /// <summary>
  25. /// Interaction logic for MainWindow.xaml
  26. /// </summary>
  27. public partial class MainWindow : Window
  28. {
  29. List<FrameworkElement> Children = new List<FrameworkElement>();
  30. public MainWindow()
  31. {
  32. InitializeComponent();
  33. xxnc.ItemsSource = System.Enum.GetNames(typeof(MessageNameEnum))?.ToList();
  34. mlname.ItemsSource = System.Enum.GetNames(typeof(MessageNameEnum))?.ToList();
  35. xx.ItemsSource = System.Enum.GetNames(typeof(RunEnum))?.ToList();
  36. }
  37. #region 加载数据
  38. /// <summary>
  39. /// 加载数据
  40. /// </summary>
  41. public void LoadingData(string path)
  42. {
  43. //加载控件
  44. Children.Clear();
  45. FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
  46. using (StreamReader sr = new StreamReader(fs, System.Text.Encoding.Unicode))
  47. {
  48. while (sr.Peek() > -1)
  49. {
  50. string str = sr.ReadLine();
  51. //if (!str.Contains("NewConveyorBelt"))
  52. {
  53. var ele = XamlReader.Parse(str) as FrameworkElement;
  54. Children.Add(ele);
  55. }
  56. }
  57. }
  58. if (Children.Count > 0)
  59. {
  60. runCanvas.Run(Children);
  61. }
  62. }
  63. #endregion
  64. private void Button_Click(object sender, RoutedEventArgs e)
  65. {
  66. OpenFileDialog ofd = new OpenFileDialog();
  67. ofd.Filter = "布局文件|*.lay";
  68. if (ofd.ShowDialog() ==true)
  69. {
  70. LoadingData(ofd.FileName);
  71. }
  72. }
  73. private void Button_Click_1(object sender, RoutedEventArgs e)
  74. {
  75. if (string.IsNullOrEmpty(mlname.Text))
  76. {
  77. MessageBox.Show("消息名称不能为空!");
  78. return;
  79. }
  80. if (string.IsNullOrEmpty(xx.Text))
  81. {
  82. MessageBox.Show("命令不能为空!");
  83. return;
  84. }
  85. RunEnumModel runEnumModel = new RunEnumModel();
  86. runEnumModel.Run = ToEnumValue<RunEnum>(xx.Text);
  87. runEnumModel.ID = hm.Text;
  88. Class_InnerMessageBus.GetInstance().PostMessage(this, mlname.Text, runEnumModel);
  89. }
  90. /// <summary>
  91. /// 根据枚举名称获取枚举值
  92. /// </summary>
  93. public T ToEnumValue<T>(string name)
  94. {
  95. return (T)Enum.Parse(typeof(T), name);
  96. }
  97. private void Button_Click_2(object sender, RoutedEventArgs e)
  98. {
  99. if (string.IsNullOrEmpty(xxnc.Text))
  100. {
  101. MessageBox.Show("消息名称不能为空!");
  102. return;
  103. }
  104. if (string.IsNullOrEmpty(ch.Text))
  105. {
  106. MessageBox.Show("仓号不能为空!");
  107. return;
  108. }
  109. if (string.IsNullOrEmpty(bt.Text))
  110. {
  111. MessageBox.Show("标题不能为空!");
  112. return;
  113. }
  114. if (string.IsNullOrEmpty(zl.Text))
  115. {
  116. MessageBox.Show("重量不能为空!");
  117. return;
  118. }
  119. SilosMessageModel silosMessage = new SilosMessageModel();
  120. silosMessage.id= ch.Text;
  121. silosMessage.Value = zl.Text;
  122. silosMessage.Title = bt.Text;
  123. Class_InnerMessageBus.GetInstance().PostMessage(this, xxnc.Text, silosMessage);
  124. }
  125. }
  126. }