CustomHouseInfo.xaml.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. using ivf_tl_Entity.GlobalEntitys;
  2. using ivf_tl_Entity.GlobalEnums;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using System.Windows.Media.Imaging;
  11. namespace ivf_tl_Operate.CustomUserControls
  12. {
  13. /// <summary>
  14. /// CustomHouseInfo.xaml 的交互逻辑
  15. /// </summary>
  16. public partial class CustomHouseInfo : UserControl
  17. {
  18. /// <summary>
  19. /// housesn
  20. /// </summary>
  21. public event Action<CustomHouseInfo> ClickHouseEvent;
  22. private int ellipseCount = 16;
  23. private double samllRadius = 21;
  24. private double centerX=0;
  25. private double centerY = 0;
  26. private double angle = 0;
  27. private double bigRadius = 115;
  28. /// <summary>
  29. /// 旋转角度
  30. /// </summary>
  31. private double angleOffset = 90;
  32. private Dictionary<int, Image> StateImageDic = new Dictionary<int, Image>();
  33. public CustomHouseInfo()
  34. {
  35. InitializeComponent();
  36. centerX = this._canvas.Width / 2;
  37. centerY = this._canvas.Height / 2;
  38. angle = 360d / ellipseCount;
  39. InitUserControl();
  40. this.IsEnabledChanged -= CustomHouseInfo_IsEnabledChanged;
  41. this.IsEnabledChanged += CustomHouseInfo_IsEnabledChanged;
  42. }
  43. private void CustomHouseInfo_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
  44. {
  45. if (this.IsEnabled)
  46. {
  47. //this.Opacity = 1;
  48. this.maskHouse.Opacity = 0;
  49. }
  50. else
  51. {
  52. //this.Opacity = 0.6;
  53. this.maskHouse.Opacity = 0.2;
  54. }
  55. }
  56. private void InitUserControl()
  57. {
  58. for (int i = 0; i < ellipseCount; i++)
  59. {
  60. Border border = new Border();
  61. this._canvas.Children.Add(border);
  62. Image image = new Image();
  63. border.Child = image;
  64. StateImageDic.Add((i+1), image);
  65. image.Width = (samllRadius - 2) * 2;
  66. image.Height = (samllRadius - 2) * 2;
  67. image.Stretch = Stretch.UniformToFill;
  68. image.Source = null;
  69. border.Width = samllRadius * 2;
  70. border.Height = samllRadius * 2;
  71. border.CornerRadius = new CornerRadius(samllRadius);
  72. border.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * bigRadius - border.Width / 2);
  73. border.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * bigRadius - border.Height / 2);
  74. border.BorderBrush = new SolidColorBrush(Color.FromArgb(255, 201, 209, 219));
  75. border.BorderThickness = new Thickness(1);
  76. border.Background = new SolidColorBrush(Colors.White);
  77. }
  78. }
  79. public ExHouse ExHouseSource
  80. {
  81. get { return (ExHouse)GetValue(ExHouseSourceProperty); }
  82. set { SetValue(ExHouseSourceProperty, value); }
  83. }
  84. // Using a DependencyProperty as the backing store for ExHouseSource. This enables animation, styling, binding, etc...
  85. public static readonly DependencyProperty ExHouseSourceProperty =
  86. DependencyProperty.Register("ExHouseSource", typeof(ExHouse), typeof(CustomHouseInfo), new PropertyMetadata(new ExHouse()));
  87. public int HouseSn
  88. {
  89. get { return (int)GetValue(HouseSnProperty); }
  90. set { SetValue(HouseSnProperty, value); }
  91. }
  92. // Using a DependencyProperty as the backing store for HouseSn. This enables animation, styling, binding, etc...
  93. public static readonly DependencyProperty HouseSnProperty =
  94. DependencyProperty.Register("HouseSn", typeof(int), typeof(CustomHouseInfo), new PropertyMetadata(0));
  95. private void _canvas_MouseUp(object sender, MouseButtonEventArgs e)
  96. {
  97. ClickHouseEvent?.Invoke(this);
  98. e.Handled = true;
  99. }
  100. public ExDish ExDishSource
  101. {
  102. get { return (ExDish)GetValue(ExDishSourceProperty); }
  103. set { SetValue(ExDishSourceProperty, value); }
  104. }
  105. public static readonly DependencyProperty ExDishSourceProperty =
  106. DependencyProperty.Register("ExDishSource", typeof(ExDish), typeof(CustomHouseInfo), new PropertyMetadata(null,new PropertyChangedCallback (ExDishSourcePropertyChanged)));
  107. private static void ExDishSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  108. {
  109. if (!(d is CustomHouseInfo source)) return;
  110. if (e.NewValue == null)
  111. {
  112. source.SetDish(source, null);
  113. return;
  114. }
  115. if(!(e.NewValue is ExDish exDish))
  116. {
  117. source.SetDish(source, null);
  118. return;
  119. }
  120. source.SetDish(source, exDish);
  121. return;
  122. }
  123. private void SetDish(CustomHouseInfo customHouseInfo, ExDish exDish)
  124. {
  125. if(exDish == null)
  126. {
  127. foreach (var item in customHouseInfo.StateImageDic)
  128. {
  129. item.Value.Source = null;
  130. }
  131. return;
  132. }
  133. foreach (var item in customHouseInfo.StateImageDic)
  134. {
  135. var embryo = exDish.embryoList.FirstOrDefault(x => x.wellSn == item.Key);
  136. if(embryo == null)
  137. {
  138. item.Value.Source = null;
  139. continue;
  140. }
  141. EmbryoState state = (EmbryoState)embryo.state;
  142. switch (state)
  143. {
  144. case EmbryoState.Freezing:
  145. item.Value.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/open_button_freezable.png", UriKind.RelativeOrAbsolute));//冷冻
  146. break;
  147. case EmbryoState.Transplant:
  148. item.Value.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/yz.png", UriKind.RelativeOrAbsolute));//移植
  149. break;
  150. case EmbryoState.Cancellation:
  151. item.Value.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/open_button_no.png", UriKind.RelativeOrAbsolute));//作废
  152. break;
  153. case EmbryoState.None:
  154. item.Value.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/yuan.png", UriKind.RelativeOrAbsolute));
  155. break;
  156. case EmbryoState.Delete:
  157. item.Value.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/menu_delete.png", UriKind.RelativeOrAbsolute));//作废
  158. break;
  159. default:
  160. item.Value.Source = null;
  161. break;
  162. }
  163. }
  164. }
  165. public void RefDish()
  166. {
  167. SetDish(this, this.ExDishSource);
  168. }
  169. public void SetEmbryoState(int well, int embryoState)
  170. {
  171. var item = StateImageDic[well];
  172. EmbryoState state = (EmbryoState)embryoState;
  173. switch (state)
  174. {
  175. case EmbryoState.Freezing:
  176. item.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/open_button_freezable.png", UriKind.RelativeOrAbsolute));//冷冻
  177. break;
  178. case EmbryoState.Transplant:
  179. item.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/yz.png", UriKind.RelativeOrAbsolute));//移植
  180. break;
  181. case EmbryoState.Cancellation:
  182. item.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/open_button_no.png", UriKind.RelativeOrAbsolute));//作废
  183. break;
  184. case EmbryoState.None:
  185. item.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/yuan.png", UriKind.RelativeOrAbsolute));
  186. break;
  187. case EmbryoState.Delete:
  188. item.Source = new BitmapImage(new Uri("/ivf_tl_Operate;component/Resources/Image/menu_delete.png", UriKind.RelativeOrAbsolute));//作废
  189. break;
  190. default:
  191. item.Source = null;
  192. break;
  193. }
  194. }
  195. private void Canvas_MouseDown(object sender, MouseButtonEventArgs e)
  196. {
  197. ClickHouseEvent?.Invoke(this);
  198. }
  199. }
  200. }