|
- using BPASmartClient.MessageCommunication;
- using BPASmartClient.MessageName;
- using BPASmartClient.MessageName.Enum.物料仓;
- using BPASmartClient.MessageName.Enum.运行状态;
- using Microsoft.Win32;
- 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
- {
- List<FrameworkElement> Children = new List<FrameworkElement>();
-
- public MainWindow()
- {
- InitializeComponent();
- xxnc.ItemsSource = System.Enum.GetNames(typeof(MessageNameEnum))?.ToList();
- mlname.ItemsSource = System.Enum.GetNames(typeof(MessageNameEnum))?.ToList();
- xx.ItemsSource = System.Enum.GetNames(typeof(RunEnum))?.ToList();
- }
-
- #region 加载数据
- /// <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)
- {
- 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.ID = 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.id= ch.Text;
- silosMessage.Value = zl.Text;
- silosMessage.Title = bt.Text;
- Class_InnerMessageBus.GetInstance().PostMessage(this, xxnc.Text, silosMessage);
-
- }
- }
- }
|