| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- using ivf_tl_Entity.GlobalEntitys;
- using ivf_tl_Entity.GlobalEnums;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- namespace ivf_tl_Operate.CustomUserControls
- {
- /// <summary>
- /// CustomHouseInfo.xaml 的交互逻辑
- /// </summary>
- public partial class CustomHouseInfo : UserControl
- {
- /// <summary>
- /// housesn
- /// </summary>
- public event Action<CustomHouseInfo> ClickHouseEvent;
- private int ellipseCount = 16;
- private double samllRadius = 21;
- private double centerX=0;
- private double centerY = 0;
- private double angle = 0;
- private double bigRadius = 115;
- /// <summary>
- /// 旋转角度
- /// </summary>
- private double angleOffset = 90;
- private Dictionary<int, Image> StateImageDic = new Dictionary<int, Image>();
- public CustomHouseInfo()
- {
- InitializeComponent();
- centerX = this._canvas.Width / 2;
- centerY = this._canvas.Height / 2;
- angle = 360d / ellipseCount;
- InitUserControl();
- this.IsEnabledChanged -= CustomHouseInfo_IsEnabledChanged;
- this.IsEnabledChanged += CustomHouseInfo_IsEnabledChanged;
- }
- private void CustomHouseInfo_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
- {
- if (this.IsEnabled)
- {
- //this.Opacity = 1;
- this.maskHouse.Opacity = 0;
- }
- else
- {
- //this.Opacity = 0.6;
- this.maskHouse.Opacity = 0.2;
- }
- }
- private void InitUserControl()
- {
- for (int i = 0; i < ellipseCount; i++)
- {
- Border border = new Border();
- this._canvas.Children.Add(border);
- Image image = new Image();
- border.Child = image;
- StateImageDic.Add((i+1), image);
- image.Width = (samllRadius - 2) * 2;
- image.Height = (samllRadius - 2) * 2;
- image.Stretch = Stretch.UniformToFill;
- image.Source = null;
- border.Width = samllRadius * 2;
- border.Height = samllRadius * 2;
- border.CornerRadius = new CornerRadius(samllRadius);
- border.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * bigRadius - border.Width / 2);
- border.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * bigRadius - border.Height / 2);
- border.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 201, 209, 219));
- border.BorderThickness = new Thickness(1);
- border.Background = new SolidColorBrush(Colors.White);
- }
- }
- public ExHouse ExHouseSource
- {
- get { return (ExHouse)GetValue(ExHouseSourceProperty); }
- set { SetValue(ExHouseSourceProperty, value); }
- }
- // Using a DependencyProperty as the backing store for ExHouseSource. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty ExHouseSourceProperty =
- DependencyProperty.Register("ExHouseSource", typeof(ExHouse), typeof(CustomHouseInfo), new PropertyMetadata(new ExHouse()));
- public int HouseSn
- {
- get { return (int)GetValue(HouseSnProperty); }
- set { SetValue(HouseSnProperty, value); }
- }
- // Using a DependencyProperty as the backing store for HouseSn. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty HouseSnProperty =
- DependencyProperty.Register("HouseSn", typeof(int), typeof(CustomHouseInfo), new PropertyMetadata(0));
- private void _canvas_MouseUp(object sender, MouseButtonEventArgs e)
- {
- ClickHouseEvent?.Invoke(this);
- e.Handled = true;
- }
- public ExDish ExDishSource
- {
- get { return (ExDish)GetValue(ExDishSourceProperty); }
- set { SetValue(ExDishSourceProperty, value); }
- }
- public static readonly DependencyProperty ExDishSourceProperty =
- DependencyProperty.Register("ExDishSource", typeof(ExDish), typeof(CustomHouseInfo), new PropertyMetadata(null,new PropertyChangedCallback (ExDishSourcePropertyChanged)));
- private static void ExDishSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (!(d is CustomHouseInfo source)) return;
- if (e.NewValue == null)
- {
- source.SetDish(source, null);
- return;
- }
- if(!(e.NewValue is ExDish exDish))
- {
- source.SetDish(source, null);
- return;
- }
- source.SetDish(source, exDish);
- return;
- }
-
- private void SetDish(CustomHouseInfo customHouseInfo, ExDish exDish)
- {
- if(exDish == null)
- {
- foreach (var item in customHouseInfo.StateImageDic)
- {
- item.Value.Source = null;
- }
- return;
- }
- foreach (var item in customHouseInfo.StateImageDic)
- {
- var embryo = exDish.embryoList.FirstOrDefault(x => x.wellSn == item.Key);
- if(embryo == null)
- {
- item.Value.Source = null;
- continue;
- }
- EmbryoState state = (EmbryoState)embryo.state;
- switch (state)
- {
- case EmbryoState.Freezing:
- item.Value.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/open_button_freezable.png", UriKind.RelativeOrAbsolute));//冷冻
- break;
- case EmbryoState.Transplant:
- item.Value.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/yz.png", UriKind.RelativeOrAbsolute));//移植
- break;
- case EmbryoState.Cancellation:
- item.Value.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/open_button_no.png", UriKind.RelativeOrAbsolute));//作废
- break;
- case EmbryoState.None:
- item.Value.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/yuan.png", UriKind.RelativeOrAbsolute));
- break;
- case EmbryoState.Delete:
- item.Value.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/menu_delete.png", UriKind.RelativeOrAbsolute));//作废
- break;
- default:
- item.Value.Source = null;
- break;
- }
- }
- }
- public void RefDish()
- {
- SetDish(this, this.ExDishSource);
- }
- public void SetEmbryoState(int well, int embryoState)
- {
- var item = StateImageDic[well];
- EmbryoState state = (EmbryoState)embryoState;
- switch (state)
- {
- case EmbryoState.Freezing:
- item.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/open_button_freezable.png", UriKind.RelativeOrAbsolute));//冷冻
- break;
- case EmbryoState.Transplant:
- item.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/yz.png", UriKind.RelativeOrAbsolute));//移植
- break;
- case EmbryoState.Cancellation:
- item.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/open_button_no.png", UriKind.RelativeOrAbsolute));//作废
- break;
- case EmbryoState.None:
- item.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/yuan.png", UriKind.RelativeOrAbsolute));
- break;
- case EmbryoState.Delete:
- item.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/menu_delete.png", UriKind.RelativeOrAbsolute));//作废
- break;
- default:
- item.Source = null;
- break;
- }
- }
- private void Canvas_MouseDown(object sender, MouseButtonEventArgs e)
- {
- ClickHouseEvent?.Invoke(this);
- }
- }
- }
|