using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Aitex.Core.RT.IOCore; using Aitex.Core.Util; namespace Aitex.Triton160.UI.Views { /// /// Interaction logic for IOView.xaml /// public partial class IOView : UserControl { private bool _isLoaded; Dictionary _dicDiButton = new Dictionary(); Dictionary _dicDoButton = new Dictionary(); Dictionary _dicDoCheckBox = new Dictionary(); Dictionary _dicAiTitle = new Dictionary(); Dictionary _dicAiValueAscii = new Dictionary(); Dictionary _dicAiValueDecimal = new Dictionary(); Dictionary _dicAiInputAscii = new Dictionary(); Dictionary _dicAiInputDecimal = new Dictionary(); Dictionary _dicAiButton = new Dictionary(); Dictionary> _dicAiDisplayConverter = new Dictionary>(); Dictionary> _dicAiSetPointConverter = new Dictionary>(); Dictionary _dicAoTitle = new Dictionary(); Dictionary _dicAoValueAscii = new Dictionary(); Dictionary _dicAoValueDecimal = new Dictionary(); Dictionary _dicAoInputAscii = new Dictionary(); Dictionary _dicAoInputDecimal = new Dictionary(); Dictionary _dicAoButton = new Dictionary(); Dictionary _dicAoCheckBox = new Dictionary(); public IOView() { InitializeComponent(); this.Loaded += new RoutedEventHandler(IOView_Loaded); } void IOView_Loaded(object sender, RoutedEventArgs e) { if (_isLoaded) return; _isLoaded = true; InitDi(); InitDo(); InitAi(); InitAo(); } private void InitDi() { List> diList = Singleton.Instance.GetIONameList(IOType.DI); foreach (var item in diList) { ToggleButton btn = new ToggleButton(); //btn.Click += new RoutedEventHandler(btn_Click); btn.Content = string.Format("DI-{0}: {1}", item.Item1, item.Item3.Substring(2)); btn.Tag = item; btn.Height = 23; btn.Padding = new Thickness(2, 0, 0, 0); btn.Margin = new Thickness(5, 3, 0, 0); btn.Width = 250; btn.FontSize = 13; btn.Foreground = new SolidColorBrush(Colors.Black); btn.Focusable = false; btn.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left; btn.Background = new SolidColorBrush(Colors.LightGray); _dicDiButton[item.Item3] = btn; diPanel.Children.Add(btn); } } private void InitDo() { List> dOList = Singleton.Instance.GetIONameList(IOType.DO); foreach (var item in dOList) { StackPanel sp = new StackPanel(); sp.Orientation = Orientation.Horizontal; Viewbox v = new Viewbox(); v.Margin = new Thickness(-1); v.Width = 30; v.Height = 30; CheckBox cb = new CheckBox(); cb.Tag = item; cb.VerticalAlignment = System.Windows.VerticalAlignment.Center; //cb.Checked += new RoutedEventHandler(cb_Checked); //cb.Unchecked += new RoutedEventHandler(cb_Unchecked); cb.Margin = new Thickness(5, 0, 2, 0); _dicDoCheckBox[item.Item3] = cb; v.Child = cb; sp.Children.Add(v); ToggleButton btn = new ToggleButton(); //btn.Click += new RoutedEventHandler(btn_Click); btn.Content = string.Format("DO-{0}: {1}", item.Item1, item.Item3.Substring(2)); btn.Tag = item; btn.Height = 25; btn.Padding = new Thickness(2, 0, 0, 0); btn.Margin = new Thickness(0, 1, 0, 0); btn.Width = 250; btn.FontSize = 13; btn.Foreground = new SolidColorBrush(Colors.Black); btn.Focusable = false; btn.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left; btn.Background = new SolidColorBrush(Colors.LightGray); _dicDoButton[item.Item3] = btn; sp.Children.Add(btn); doPanel.Children.Add(sp); } } void InitAi() { List> diList = IO.GetIONameList(IOType.AI); foreach (var item in diList) { StackPanel sp = new StackPanel(); sp.Orientation = Orientation.Vertical; sp.Margin = new Thickness(5, 5, 0, 0); sp.Background = new SolidColorBrush(Colors.LightGray); sp.Width = 240; sp.Height = 90; //----------------Line 1 TextBlock tb = new TextBlock(); tb.Text = string.Format("AI-{0}: {1}", item.Item1, item.Item3.Substring(3)); tb.Tag = item; tb.Height = 25; tb.Margin = new Thickness(2, 5, 0, 0); tb.Padding = new Thickness(3, 0, 0, 0); tb.TextAlignment = TextAlignment.Left; tb.FontSize = 13; tb.Width = 240; _dicAiTitle[item.Item3] = tb; sp.Children.Add(tb); //--------------Line 2 StackPanel sp1 = new StackPanel(); sp1.Orientation = Orientation.Horizontal; Label lb = new Label(); lb.BorderThickness = new Thickness(1); lb.BorderBrush = new SolidColorBrush(Colors.DimGray); lb.Width = 80; lb.Height = 25; lb.FontSize = 13; lb.Tag = item; lb.Margin = new Thickness(2, 2, 0, 0); _dicAiValueAscii[item.Item3] = lb; sp1.Children.Add(lb); lb = new Label(); lb.BorderThickness = new Thickness(1); lb.BorderBrush = new SolidColorBrush(Colors.DimGray); lb.Width = 80; lb.Height = 25; lb.FontSize = 13; lb.Tag = item; lb.Margin = new Thickness(2, 2, 0, 0); _dicAiValueDecimal[item.Item3] = lb; sp1.Children.Add(lb); sp.Children.Add(sp1); //--------------Line 3 StackPanel sp2 = new StackPanel(); sp2.Orientation = Orientation.Horizontal; lb = new Label(); lb.BorderThickness = new Thickness(1); lb.BorderBrush = new SolidColorBrush(Colors.DimGray); lb.Width = 80; lb.Height = 25; lb.FontSize = 13; lb.Tag = item; lb.Margin = new Thickness(2, 2, 0, 0); _dicAiInputAscii[item.Item3] = lb; sp2.Children.Add(lb); TextBox text = new TextBox(); text.Tag = item; text.Width = 80; text.Height = 25; text.Margin = new Thickness(2, 2, 0, 0); //text.PreviewKeyDown += new KeyEventHandler(text_PreviewKeyDown); //text.PreviewTextInput += new TextCompositionEventHandler(text_PreviewTextInput); _dicAiInputDecimal[item.Item3] = text; sp2.Children.Add(text); Button btn = new Button(); //btn.Click += new RoutedEventHandler(btn_Click); btn.Content = "设置"; btn.Tag = item; btn.Height = 25; btn.Padding = new Thickness(2, 0, 0, 0); btn.Margin = new Thickness(3, 1, 0, 0); btn.Width = 60; btn.FontSize = 13; btn.Focusable = false; _dicAiButton[item.Item3] = btn; sp2.Children.Add(btn); sp.Children.Add(sp2); aiPanel.Children.Add(sp); } } void InitAo( ) { List> diList = Singleton.Instance.GetIONameList(IOType.AO); foreach (var item in diList) { StackPanel sp = new StackPanel(); sp.Orientation = Orientation.Vertical; sp.Margin = new Thickness(5, 5, 0, 0); sp.Background = new SolidColorBrush(Colors.LightGray); sp.Width = 240; sp.Height = 90; //----------------Line 1 StackPanel sp0 = new StackPanel(); sp0.Orientation = Orientation.Horizontal; Viewbox v = new Viewbox(); //v.Margin = new Thickness(-1); v.Width = 30; v.Height = 30; CheckBox cb = new CheckBox(); cb.Tag = item; cb.VerticalAlignment = System.Windows.VerticalAlignment.Center; //cb.Checked += new RoutedEventHandler(cb_Checked); //cb.Unchecked += new RoutedEventHandler(cb_Unchecked); cb.Margin = new Thickness(5, 0, 2, 0); _dicAoCheckBox[item.Item3] = cb; v.Child = cb; sp0.Children.Add(v); TextBlock tb = new TextBlock(); tb.Text = string.Format("AO-{0}: {1}", item.Item1, item.Item3.Substring(3)); tb.Tag = item; tb.Height = 25; tb.Margin = new Thickness(2, 5, 0, 0); tb.Padding = new Thickness(3, 0, 0, 0); tb.TextAlignment = TextAlignment.Left; tb.FontSize = 13; tb.Width = 240; sp0.Children.Add(tb); sp.Children.Add(sp0); //--------------Line 2 StackPanel sp1 = new StackPanel(); sp1.Orientation = Orientation.Horizontal; Label lb = new Label(); lb.BorderThickness = new Thickness(1); lb.BorderBrush = new SolidColorBrush(Colors.DimGray); lb.Width = 80; lb.Height = 25; lb.FontSize = 13; lb.Tag = item; lb.Margin = new Thickness(2, 2, 0, 0); _dicAoValueAscii[item.Item3] = lb; sp1.Children.Add(lb); lb = new Label(); lb.BorderThickness = new Thickness(1); lb.BorderBrush = new SolidColorBrush(Colors.DimGray); lb.Width = 80; lb.Height = 25; lb.FontSize = 13; lb.Tag = item; lb.Margin = new Thickness(2, 2, 0, 0); _dicAoValueDecimal[item.Item3] = lb; sp1.Children.Add(lb); sp.Children.Add(sp1); //--------------Line 3 StackPanel sp2 = new StackPanel(); sp2.Orientation = Orientation.Horizontal; lb = new Label(); lb.BorderThickness = new Thickness(1); lb.BorderBrush = new SolidColorBrush(Colors.DimGray); lb.Width = 80; lb.Height = 25; lb.FontSize = 13; lb.Tag = item; lb.Margin = new Thickness(2, 2, 0, 0); _dicAoInputAscii[item.Item3] = lb; sp2.Children.Add(lb); TextBox text = new TextBox(); text.Tag = item; text.Width = 80; text.Height = 25; text.Margin = new Thickness(2, 2, 0, 0); _dicAoInputDecimal[item.Item3] = text; sp2.Children.Add(text); Button btn = new Button(); //btn.Click += new RoutedEventHandler(btn_Click); btn.Content = "设置"; btn.Tag = item; btn.Height = 25; btn.Padding = new Thickness(2, 0, 0, 0); btn.Margin = new Thickness(3, 1, 0, 0); btn.Width = 60; btn.FontSize = 13; btn.Focusable = false; btn.IsEnabled = false; _dicAoButton[item.Item3] = btn; sp2.Children.Add(btn); sp.Children.Add(sp2); aoPanel.Children.Add(sp); } } } }