using ivf_tl_Entity.Entity.balance;
using ivf_tl_Entity.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
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 ivf_tl_Manage.UserControls
{
///
/// DishInfoUserControl.xaml 的交互逻辑
///
public partial class DishInfoUserControl : UserControl
{
public event Action EditAndAddClickEvent;
public event Action DetailAndAddClickEvent;
public DishInfoUserControl()
{
InitializeComponent();
centerX = 280 / 2.0;
centerY = 280 / 2.0;
angle = 360.00 / 16;
InitCustom();
this.IsEnabledChanged -= DishInfoUserControl_IsEnabledChanged;
this.IsEnabledChanged += DishInfoUserControl_IsEnabledChanged;
}
private void DishInfoUserControl_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (this.IsEnabled)
{
this.maskHouse.Opacity = 0;
}
else
{
this.maskHouse.Opacity = 0.2;
}
}
private Dictionary EmbryoStateImageList = new Dictionary();
private double centerX, centerY;
private double angle;
private double angleOffset = 90;
private int ellipseCount = 16;
//19
private int imageRadius = 18;
//95
private int imageBigRadius = 100;
private int textRadius = 77;
private void InitCustom()
{
try
{
for (int i = 0; i < ellipseCount; i++)
{
Image border = new Image();
TextBlock textBlock = new TextBlock();
this._canvas.Children.Add(border);
this._canvas.Children.Add(textBlock);
textBlock.Text = $"{i+1}";
textBlock.TextAlignment = TextAlignment.Center;
textBlock.FontWeight = FontWeights.Medium;
textBlock.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9B9B9B"));
//textBlock.Foreground = new SolidColorBrush(Colors.Red);
//textBlock.Background = new SolidColorBrush(Colors.LightBlue);
textBlock.FontSize = 9.5;
textBlock.Width = 12;
textBlock.Height = 14;
textBlock.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * textRadius - 6);
textBlock.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * textRadius - 7);
EmbryoStateImageList.Add((i + 1), border);
border.Name = $"B{i + 1}";
border.Width = imageRadius * 2;
border.Height = imageRadius * 2;
border.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/NoEmbryoYuanIcon.png", UriKind.Absolute));
border.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - imageRadius);
border.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - imageRadius);
}
}
catch (Exception)
{
throw;
}
}
public House HouseSource
{
get { return (House)GetValue(HouseSourceProperty); }
set { SetValue(HouseSourceProperty, value); }
}
// Using a DependencyProperty as the backing store for HouseSource. This enables animation, styling, binding, etc...
public static readonly DependencyProperty HouseSourceProperty =
DependencyProperty.Register("HouseSource", typeof(House), typeof(DishInfoUserControl), new PropertyMetadata(new House(), new PropertyChangedCallback(HouseSourcePropertyChangedCallback)));
private static void HouseSourcePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (!(d is DishInfoUserControl source)) return;
if (e.NewValue == null)
{
source.SetDish(source, null);
return;
}
if (!(e.NewValue is House house))
{
source.SetDish(source, null);
return;
}
if(house.houseSn == 3)
{
string ss = "";
}
source.SetDish(source, house.embryoRecordVO);
return;
}
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(DishInfoUserControl), new PropertyMetadata(0));
public string TLSN
{
get { return (string)GetValue(TLSNProperty); }
set { SetValue(TLSNProperty, value); }
}
// Using a DependencyProperty as the backing store for TLSN. This enables animation, styling, binding, etc...
public static readonly DependencyProperty TLSNProperty =
DependencyProperty.Register("TLSN", typeof(string), typeof(DishInfoUserControl), new PropertyMetadata(null));
public int OnLine
{
get { return (int)GetValue(OnLineProperty); }
set { SetValue(OnLineProperty, value); }
}
// Using a DependencyProperty as the backing store for OnLine. This enables animation, styling, binding, etc...
public static readonly DependencyProperty OnLineProperty =
DependencyProperty.Register("OnLine", typeof(int), typeof(DishInfoUserControl), new PropertyMetadata(1));
private void Edit_Click(object sender, RoutedEventArgs e)
{
if (!this.IsLoaded) return;
EditAndAddClickEvent?.Invoke(this,HouseSource, TLSN);
e.Handled = true;
}
private void Add_Click(object sender, RoutedEventArgs e)
{
if (!this.IsLoaded) return;
EditAndAddClickEvent?.Invoke(this,HouseSource, TLSN);
e.Handled = true;
}
private void _canvas_MouseUp(object sender, MouseButtonEventArgs e)
{
if (!this.IsLoaded) return;
DetailAndAddClickEvent?.Invoke(this,HouseSource, TLSN);
e.Handled = true;
}
public void SetDish(DishInfoUserControl source, Dish dish)
{
if (dish == null || dish.embryoList == null || !dish.embryoList.Any())
{
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));
return;
}
foreach (var item in source.EmbryoStateImageList)
{
var currentEmbryo = dish.embryoList.FirstOrDefault(x => x.wellSn == item.Key);
if (currentEmbryo == null)
{
item.Value.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/NoEmbryoYuanIcon.png", UriKind.Absolute));
continue;
}
EmbryoState state = (EmbryoState)currentEmbryo.state;
switch (state)
{
case EmbryoState.None:
item.Value.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoYuanIcon.png", UriKind.Absolute));
break;
case EmbryoState.Freezing:
item.Value.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoFreezingIcon.png", UriKind.Absolute));//冷冻
break;
case EmbryoState.Transplant:
item.Value.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoTransplantIcon.png", UriKind.Absolute));//移植
break;
case EmbryoState.Cancellation:
item.Value.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoCancellationIcon.png", UriKind.Absolute));//作废
break;
case EmbryoState.Delete:
item.Value.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoDeleteIcon.png", UriKind.Absolute));//删除
break;
default:
item.Value.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoYuanIcon.png", UriKind.Absolute));
break;
}
}
}
}
}