123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- using Aitex.Core.Common.DeviceData;
- using MECF.Framework.Common.OperationCenter;
- using MECF.Framework.UI.Core.Control;
- using System;
- using System.Collections.Generic;
- 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.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace Aitex.Core.UI.Control
- {
- /// <summary>
- /// ValveControl.xaml 的交互逻辑
- /// </summary>
- public partial class ValveControl : UserControl
- {
- public static readonly DependencyProperty CommandProperty = DependencyProperty.Register(
- "Command", typeof(ICommand), typeof(ValveControl),
- new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
- public ICommand Command
- {
- get
- {
- return (ICommand)this.GetValue(CommandProperty);
- }
- set
- {
- this.SetValue(CommandProperty, value);
- }
- }
- public Window AITGasOwner { get; set; }
- private SwitchDialog dialog;
- public bool IsVirtualSwitchOpen { get; set; }
- public bool IsEnableMouseRight
- {
- get { return (bool)GetValue(IsEnableMouseRightProperty); }
- set { SetValue(IsEnableMouseRightProperty, value); }
- }
- // Using a DependencyProperty as the backing store for IsEnableMouseRight. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty IsEnableMouseRightProperty =
- DependencyProperty.Register("IsEnableMouseRight", typeof(bool), typeof(ValveControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
- public bool IsOpen
- {
- get
- {
- return (bool)this.GetValue(IsOpenProperty);
- }
- set
- {
- this.SetValue(IsOpenProperty, value);
- }
- }
- public static readonly DependencyProperty IsOpenProperty = DependencyProperty.Register(
- "IsOpen", typeof(bool), typeof(ValveControl),
- new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
- public static readonly DependencyProperty EnableServiceControlProperty = DependencyProperty.Register(
- "EnableServiceControl", typeof(bool), typeof(ValveControl),
- new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
- public bool EnableServiceControl
- {
- get
- {
- return (bool)this.GetValue(EnableServiceControlProperty);
- }
- set
- {
- this.SetValue(EnableServiceControlProperty, value);
- }
- }
- public static readonly DependencyProperty DeviceDataProperty = DependencyProperty.Register(
- "DeviceData", typeof(AITValveData), typeof(ValveControl),
- new FrameworkPropertyMetadata(new AITValveData(), FrameworkPropertyMetadataOptions.AffectsRender));
- public AITValveData DeviceData
- {
- get
- {
- var data = (AITValveData)this.GetValue(DeviceDataProperty);
- return data;
- }
- set
- {
- this.SetValue(DeviceDataProperty, value);
- }
- }
- private int _rotationAngle;
- public int RotationAngle
- {
- get => _rotationAngle;
- set
- {
- _rotationAngle = value;
- canvasRotate.Angle = _rotationAngle;
- }
- }
- public ValveControl()
- {
- InitializeComponent();
- IsEnableMouseRight = false;
- }
- protected override void OnRender(DrawingContext drawingContext)
- {
- base.OnRender(drawingContext);
- if (IsOpen)
- {
- imgClose.Visibility = Visibility.Hidden;
- imgOpen.Visibility = Visibility.Visible;
- }
- else
- {
- imgClose.Visibility = Visibility.Visible;
- imgOpen.Visibility = Visibility.Hidden;
- }
- }
- /// <summary>
- /// open
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void TurnOnValve(object sender, RoutedEventArgs e)
- {
- if (EnableServiceControl)
- {
- IsOpen = true;
- InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", true);
- this.UpdateLayout();
- }
- }
- /// <summary>
- /// close
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void TurnOffValve(object sender, RoutedEventArgs e)
- {
- IsOpen = false;
- InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", false);
- this.UpdateLayout();
- }
- private void nopass_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- if (DeviceData == null || string.IsNullOrEmpty(DeviceData.DeviceName))
- return;
- ContextMenu mouseClickMenu = new ContextMenu();
- MenuItem item = new MenuItem();
- item.Header = "_" + DeviceData.DisplayName;
- item.Background = Brushes.Gray;
- item.Foreground = Brushes.White;
- item.IsEnabled = false;
- mouseClickMenu.Items.Add(item);
- addOpenMenu(mouseClickMenu, item, false);
- addCloseMenu(mouseClickMenu, item, false);
- mouseClickMenu.IsOpen = true;
- }
- private void passtrigle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- if (DeviceData == null || string.IsNullOrEmpty(DeviceData.DeviceName))
- return;
- ContextMenu mouseClickMenu = new ContextMenu();
- MenuItem item = new MenuItem();
- item.Header = "_" + DeviceData.DeviceName;
- item.Background = Brushes.Gray;
- item.Foreground = Brushes.White;
- item.IsEnabled = false;
- mouseClickMenu.Items.Add(item);
- addCloseMenu(mouseClickMenu, item, true);
- addOpenMenu(mouseClickMenu, item, true);
- mouseClickMenu.IsOpen = true;
- }
- void addOpenMenu(ContextMenu mouseClickMenu, MenuItem item, bool isEnable)
- {
- item = new MenuItem();
- item.Header = "打开 (_O)";
- item.Click += TurnOnValve;
- item.Tag = this.Tag;
- item.IsEnabled = isEnable;
- mouseClickMenu.Items.Add(item);
- }
- void addCloseMenu(ContextMenu mouseClickMenu, MenuItem item, bool isEnable)
- {
- item = new MenuItem();
- item.Header = "关闭 (_C)";
- item.Tag = this.Tag;
- item.Click += TurnOffValve;
- item.IsEnabled = isEnable;
- mouseClickMenu.Items.Add(item);
- }
- private void imgValve_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
- {
- if (!IsEnableMouseRight)
- { return; }
- if (EnableServiceControl)
- {
- passtrigle_MouseLeftButtonDown(null, null);
- }
- else
- {
- nopass_MouseLeftButtonDown(null, null);
- }
- }
- private void imgValve_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
- {
- if (!IsEnableMouseRight)
- { return; }
- dialog = new SwitchDialog { };
- dialog.IsOpen = EnableServiceControl ? IsOpen : IsVirtualSwitchOpen;
- dialog.Owner = AITGasOwner;
- dialog.Topmost = true;
- //dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;
- dialog.DeviceName = "Valve Name: " + DeviceData.DeviceName.Replace("Valve", "");
- //var point = this.PointFromScreen(new Point(0, 0));
- var point = System.Windows.Forms.Control.MousePosition;
- double x = SystemParameters.WorkArea.Width;
- double y = SystemParameters.WorkArea.Height;
- if (point.Y + this.ActualHeight + 15 + dialog.Height < y)
- {
- dialog.Top = point.Y + dialog.ActualHeight + 15;
- }
- else
- {
- dialog.Top = point.Y - dialog.Height - 15;
- }
- if (point.X + dialog.Width < x)
- {
- dialog.Left = point.X;
- }
- else
- {
- dialog.Left = point.X - (dialog.Width - this.ActualWidth);
- }
- //Point centerP = new Point(dialog.Left + 100, dialog.Top + 100);
- //MoveMouseToPoint(centerP);
- dialog.ShowDialog();
- if ((bool)dialog.IsSave)
- {
- if (EnableServiceControl)
- {
- IsOpen = dialog.IsOpen;
- InvokeClient.Instance.Service.DoOperation($"{DeviceData.UniqueName}.{AITValveOperation.GVTurnValve}", dialog.IsOpen);
- return;
- }
- // IsVirtualSwitchOpen = dialog.IsOpen;
- if (Command == null)
- return;
- //Command.Execute(new object[] { DeviceData.UniqueName, AITValveOperation.GVVirtualTurnValve, dialog.IsOpen });
- //if (DeviceData2 != null && !string.IsNullOrEmpty(DeviceData2.DeviceName))
- //{
- // Command.Execute(new object[] { DeviceData2.DeviceName, AITValveOperation.GVTurnValve, !dialog.IsOpen });
- //}
- }
- }
- }
- }
|