DishInfoUserControl.xaml.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. using ivf_tl_Entity.Entity.balance;
  2. using ivf_tl_Entity.Enums;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Reflection.Metadata;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Navigation;
  17. using System.Windows.Shapes;
  18. namespace ivf_tl_Manage.UserControls
  19. {
  20. /// <summary>
  21. /// DishInfoUserControl.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class DishInfoUserControl : UserControl
  24. {
  25. public event Action<DishInfoUserControl,House, string> EditAndAddClickEvent;
  26. public event Action<DishInfoUserControl,House, string> DetailAndAddClickEvent;
  27. public DishInfoUserControl()
  28. {
  29. InitializeComponent();
  30. centerX = 280 / 2.0;
  31. centerY = 280 / 2.0;
  32. angle = 360.00 / 16;
  33. InitCustom();
  34. this.IsEnabledChanged -= DishInfoUserControl_IsEnabledChanged;
  35. this.IsEnabledChanged += DishInfoUserControl_IsEnabledChanged;
  36. }
  37. private void DishInfoUserControl_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
  38. {
  39. if (this.IsEnabled)
  40. {
  41. this.maskHouse.Opacity = 0;
  42. }
  43. else
  44. {
  45. this.maskHouse.Opacity = 0.2;
  46. }
  47. }
  48. private Dictionary<int, Image> EmbryoStateImageList = new Dictionary<int, Image>();
  49. private double centerX, centerY;
  50. private double angle;
  51. private double angleOffset = 90;
  52. private int ellipseCount = 16;
  53. //19
  54. private int imageRadius = 18;
  55. //95
  56. private int imageBigRadius = 100;
  57. private int textRadius = 77;
  58. private void InitCustom()
  59. {
  60. try
  61. {
  62. for (int i = 0; i < ellipseCount; i++)
  63. {
  64. Image border = new Image();
  65. TextBlock textBlock = new TextBlock();
  66. this._canvas.Children.Add(border);
  67. this._canvas.Children.Add(textBlock);
  68. textBlock.Text = $"{i+1}";
  69. textBlock.TextAlignment = TextAlignment.Center;
  70. textBlock.FontWeight = FontWeights.Medium;
  71. textBlock.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9B9B9B"));
  72. //textBlock.Foreground = new SolidColorBrush(Colors.Red);
  73. //textBlock.Background = new SolidColorBrush(Colors.LightBlue);
  74. textBlock.FontSize = 9.5;
  75. textBlock.Width = 12;
  76. textBlock.Height = 14;
  77. textBlock.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * textRadius - 6);
  78. textBlock.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * textRadius - 7);
  79. EmbryoStateImageList.Add((i + 1), border);
  80. border.Name = $"B{i + 1}";
  81. border.Width = imageRadius * 2;
  82. border.Height = imageRadius * 2;
  83. border.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/NoEmbryoYuanIcon.png", UriKind.Absolute));
  84. border.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - imageRadius);
  85. border.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - imageRadius);
  86. }
  87. }
  88. catch (Exception)
  89. {
  90. throw;
  91. }
  92. }
  93. public House HouseSource
  94. {
  95. get { return (House)GetValue(HouseSourceProperty); }
  96. set { SetValue(HouseSourceProperty, value); }
  97. }
  98. // Using a DependencyProperty as the backing store for HouseSource. This enables animation, styling, binding, etc...
  99. public static readonly DependencyProperty HouseSourceProperty =
  100. DependencyProperty.Register("HouseSource", typeof(House), typeof(DishInfoUserControl), new PropertyMetadata(new House(), new PropertyChangedCallback(HouseSourcePropertyChangedCallback)));
  101. private static void HouseSourcePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  102. {
  103. if (!(d is DishInfoUserControl source)) return;
  104. if (e.NewValue == null)
  105. {
  106. source.SetDish(source, null);
  107. return;
  108. }
  109. if (!(e.NewValue is House house))
  110. {
  111. source.SetDish(source, null);
  112. return;
  113. }
  114. if(house.houseSn == 3)
  115. {
  116. string ss = "";
  117. }
  118. source.SetDish(source, house.embryoRecordVO);
  119. return;
  120. }
  121. public int HouseSn
  122. {
  123. get { return (int)GetValue(HouseSnProperty); }
  124. set { SetValue(HouseSnProperty, value); }
  125. }
  126. // Using a DependencyProperty as the backing store for HouseSn. This enables animation, styling, binding, etc...
  127. public static readonly DependencyProperty HouseSnProperty =
  128. DependencyProperty.Register("HouseSn", typeof(int), typeof(DishInfoUserControl), new PropertyMetadata(0));
  129. public string TLSN
  130. {
  131. get { return (string)GetValue(TLSNProperty); }
  132. set { SetValue(TLSNProperty, value); }
  133. }
  134. // Using a DependencyProperty as the backing store for TLSN. This enables animation, styling, binding, etc...
  135. public static readonly DependencyProperty TLSNProperty =
  136. DependencyProperty.Register("TLSN", typeof(string), typeof(DishInfoUserControl), new PropertyMetadata(null));
  137. public int OnLine
  138. {
  139. get { return (int)GetValue(OnLineProperty); }
  140. set { SetValue(OnLineProperty, value); }
  141. }
  142. // Using a DependencyProperty as the backing store for OnLine. This enables animation, styling, binding, etc...
  143. public static readonly DependencyProperty OnLineProperty =
  144. DependencyProperty.Register("OnLine", typeof(int), typeof(DishInfoUserControl), new PropertyMetadata(1));
  145. private void Edit_Click(object sender, RoutedEventArgs e)
  146. {
  147. if (!this.IsLoaded) return;
  148. EditAndAddClickEvent?.Invoke(this,HouseSource, TLSN);
  149. e.Handled = true;
  150. }
  151. private void Add_Click(object sender, RoutedEventArgs e)
  152. {
  153. if (!this.IsLoaded) return;
  154. EditAndAddClickEvent?.Invoke(this,HouseSource, TLSN);
  155. e.Handled = true;
  156. }
  157. private void _canvas_MouseUp(object sender, MouseButtonEventArgs e)
  158. {
  159. if (!this.IsLoaded) return;
  160. DetailAndAddClickEvent?.Invoke(this,HouseSource, TLSN);
  161. e.Handled = true;
  162. }
  163. public void SetDish(DishInfoUserControl source, Dish dish)
  164. {
  165. if (dish == null || dish.embryoList == null || !dish.embryoList.Any())
  166. {
  167. foreach (var item in source.EmbryoStateImageList) item.Value.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/NoEmbryoYuanIcon.png", UriKind.Absolute));
  168. return;
  169. }
  170. foreach (var item in source.EmbryoStateImageList)
  171. {
  172. var currentEmbryo = dish.embryoList.FirstOrDefault(x => x.wellSn == item.Key);
  173. if (currentEmbryo == null)
  174. {
  175. item.Value.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/NoEmbryoYuanIcon.png", UriKind.Absolute));
  176. continue;
  177. }
  178. EmbryoState state = (EmbryoState)currentEmbryo.state;
  179. switch (state)
  180. {
  181. case EmbryoState.None:
  182. item.Value.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoYuanIcon.png", UriKind.Absolute));
  183. break;
  184. case EmbryoState.Freezing:
  185. item.Value.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoFreezingIcon.png", UriKind.Absolute));//冷冻
  186. break;
  187. case EmbryoState.Transplant:
  188. item.Value.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoTransplantIcon.png", UriKind.Absolute));//移植
  189. break;
  190. case EmbryoState.Cancellation:
  191. item.Value.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoCancellationIcon.png", UriKind.Absolute));//作废
  192. break;
  193. case EmbryoState.Delete:
  194. item.Value.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoDeleteIcon.png", UriKind.Absolute));//删除
  195. break;
  196. default:
  197. item.Value.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoYuanIcon.png", UriKind.Absolute));
  198. break;
  199. }
  200. }
  201. }
  202. }
  203. }