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 { /// /// CustomHouseInfo.xaml 的交互逻辑 /// public partial class CustomHouseInfo : UserControl { /// /// housesn /// public event Action 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; /// /// 旋转角度 /// private double angleOffset = 90; private Dictionary StateImageDic = new Dictionary(); 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); } } }