| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- using ivf_tl_Entity.Entity.balance;
- using ivf_tl_Entity.Enums;
- using ivf_tl_Manage.Converts;
- using ivf_tl_Manage.ViewModels.Win;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- namespace ivf_tl_Manage.Win
- {
- /// <summary>
- /// AddDishWindow.xaml 的交互逻辑
- /// </summary>
- public partial class AddDishWindow : Window
- {
- public AddDishWindowViewModel vm = null;
- private Balance currentBalance { get; set; }
- public AddDishWindow(Dish dish, Balance balance, Window w)
- {
- InitializeComponent();
- this.Owner = w;
- centerX = 352 / 2.0;
- centerY = 362 / 2.0;
- angle = 360.00 / 16;
- vm = new AddDishWindowViewModel(dish);
- currentBalance = balance;
- this.DataContext = vm;
- InitCustom();
- }
- private Dictionary<int, Image> EmbryoStateImageList = new Dictionary<int, Image>();
- private double centerX, centerY;
- private double angle;
- private double angleOffset = 90;
- private int ellipseCount = 16;
- private int imageRadius = 22;
- //115
- private int imageBigRadius = 120;
- //65
- private int textRadius = 93;
- private void InitCustom()
- {
- try
- {
- //List<PictureEntity> picList = new List<PictureEntity>();
- //if (vm.CurrentDish != null && vm.CurrentDish.id > 0)
- //{
- // var pro = AppData.Instance.GetDishProvider();
- // var wellIdList = vm.CurrentDish.embryoList.Select(x => x.id).ToList();
- // if (wellIdList.Any())
- // {
- // picList = pro.GetNewPicApi(vm.CurrentDish.tlSn, vm.CurrentDish.houseSn, wellIdList);
- // }
- //}
- int currentWell = 1;
- //EllipseGeometry ellipseGeometry = new EllipseGeometry(new Point(imageRadius-2, imageRadius-2), imageRadius-2, imageRadius-2);
- for (int i = 0; i < ellipseCount; i++)
- {
- currentWell = i + 1;
- TextBlock textBlock = new TextBlock();
- Image border = new Image();
- textBlock.Text = $"{currentWell}";
- 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 = 10;
- 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);
- Panel.SetZIndex(textBlock, 7);
- Panel.SetZIndex(border, 6);
- this._canvas.Children.Add(textBlock);
- this._canvas.Children.Add(border);
-
- border.Name = $"B{currentWell}";
- EmbryoStateImageList.Add(currentWell, border);
- border.Width = imageRadius * 2;
- border.Height = imageRadius * 2;
- border.Tag = false;
- 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);
-
- var embryo = vm.CurrentDish.embryoList.FirstOrDefault(a => a.wellSn == currentWell);
- if (embryo == null)
- {
- border.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/NoEmbryoYuanIcon.png", UriKind.Absolute));
- border.MouseUp += (s, e) =>
- {
- var sender = s as Image;
- sender.Tag = !(bool)sender.Tag;
- if ((bool)sender.Tag == true) border.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EditEmbryoSelectedIcon.png", UriKind.Absolute));
- else border.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/NoEmbryoYuanIcon.png", UriKind.Absolute));
- if (vm.CurrentDish.id > 0) return;
- if (EmbryoStateImageList.FirstOrDefault(x => (bool)x.Value.Tag).Value == null)
- vm.IsEmbryo = 0;
- else vm.IsEmbryo = 1;
- };
- }
- else
- {
- string imageUrl = null;
- //var currentPic= picList.FirstOrDefault(x => x.wellSn == embryo.wellSn);
- //if (currentPic != null) imageUrl = $"{AppData.Instance.BaseUrl}{currentPic.imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}";
- //if(imageUrl != null)
- //{
- // border.Source = new BitmapImage(new Uri(imageUrl, UriKind.Absolute));
- // border.SetValue(Image.ClipProperty, ellipseGeometry);
- // continue;
- //}
- EmbryoState state = (EmbryoState)embryo.state;
- switch (state)
- {
- case EmbryoState.None:
- imageUrl= "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoYuanIcon.png";
- break;
- case EmbryoState.Freezing://冷冻
- imageUrl = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoFreezingIcon.png";
- break;
- case EmbryoState.Transplant://移植
- imageUrl = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoTransplantIcon.png";
- break;
- case EmbryoState.Cancellation://作废
- imageUrl = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoCancellationIcon.png";
- break;
- case EmbryoState.Delete://删除
- imageUrl = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoDeleteIcon.png";
- break;
- default:
- imageUrl = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoYuanIcon.png";
- break;
- }
- border.Source = new BitmapImage(new Uri(imageUrl, UriKind.Absolute));
- }
- }
- if (vm.CurrentDish != null && vm.CurrentDish.id > 0)
- {
- this._balance_Button.Visibility = Visibility.Hidden;
- return;
- }
- if (currentBalance != null && currentBalance.id > 0)
- {
- this._balanceStop_Button.Visibility = Visibility.Visible;
- return;
- }
- this._balance_Button.Visibility = Visibility.Visible;
- }
- catch (Exception)
- {
- }
- }
- private void ExLog(Exception ex, string name)
- {
- AppData.Instance.LogService.ExceptionLog(ex, $"AddDishWindow.{name}", LogEnum.RunException);
- }
- private void ErrorLog(string message, LogEnum logType)
- {
- AppData.Instance.LogService.TLLog($"AddDishWindow.{message}", logType);
- }
- private void DefeatMessage(string message)
- {
- this._message.Text = message;
- }
- private void Ok_Click(object sender, RoutedEventArgs e)
- {
- this.DialogResult = false;
- }
- private void StartBalance_Click(object sender, RoutedEventArgs e)
- {
- if (vm == null) return;
- var error = vm.StartBalance();
- if (string.IsNullOrEmpty(error))
- {
- this.DialogResult = true;
- return;
- }
- //DefeatMessage($"开启平衡失败:{error}");
- DefeatMessage($"{KeyToStringConvert.GetLanguageStringByKey("0313")}:{error}");
- }
- private void StopBalance_Click(object sender, RoutedEventArgs e)
- {
- if (vm == null || currentBalance == null) return;
- if (currentBalance.id <= 0) return;
- var error = vm.StopBalance(currentBalance.id);
- if (string.IsNullOrEmpty(error))
- {
- this.DialogResult = true;
- return;
- }
- //DefeatMessage($"结束平衡失败:{error}");
- DefeatMessage($"{KeyToStringConvert.GetLanguageStringByKey("0314")}:{error}");
- }
- private void StartDish_Click(object sender, RoutedEventArgs e)
- {
- //MessageBox.Show($"{vm.FerYear}-{vm.FerMonth}-{vm.FerDay} {vm.FerHour}:{vm.FerMin}");
- //return;
- //Thread.Sleep(1000 * 5);
- if (vm.CurrentDish.wife.Length > 100 || vm.CurrentDish.husband.Length > 100)
- {
- //DefeatMessage("姓名长度不能超过100个字符");
- DefeatMessage(KeyToStringConvert.GetLanguageStringByKey("0315"));
- return;
- }
- List<int> newWellSnList = null;
- if (vm.CurrentDish.id == 0 && vm.IsEmbryo == 0)
- {
- //DefeatMessage("未选择胚胎");
- DefeatMessage(KeyToStringConvert.GetLanguageStringByKey("0303"));
- return;
- }
- newWellSnList = EmbryoStateImageList.Where(x => (bool)x.Value.Tag).Select(x => x.Key).ToList();
- if (vm.CurrentDish.id == 0)
- {
- string startDishResult = vm.StartDish(newWellSnList);
- if (!string.IsNullOrEmpty(startDishResult))
- {
- DefeatMessage(startDishResult);
- return;
- }
- this.DialogResult = true;
- return;
- }
- foreach (var item in vm.CurrentDish.embryoList)
- {
- newWellSnList.Add(item.wellSn);
- }
- string updateResult = vm.UpdateDish(newWellSnList);
- if (!string.IsNullOrEmpty(updateResult))
- {
- DefeatMessage(updateResult);
- return;
- }
- this.DialogResult = true;
- return;
- }
- bool isOneOpen = false;
- private void ComBoxCustomTime_DropDownOpened(object sender, EventArgs e)
- {
- if (isOneOpen) return;
- isOneOpen = true;
- if (vm.CurrentDish.id == 0)
- {
- var dateNow = DateTime.Now;
- vm.FerYear = dateNow.Year;
- vm.FerMonth = dateNow.Month;
- vm.FerDay = dateNow.Day;
- vm.FerHour = dateNow.Hour;
- vm.FerMin = dateNow.Minute;
- }
- ListBoxScrollIntoView(this._ferTime_ComBoxCustomTime.Template.FindName("yearListBox", this._ferTime_ComBoxCustomTime), vm.FerYear, vm.YearsList);
- ListBoxScrollIntoView(this._ferTime_ComBoxCustomTime.Template.FindName("monthListBox", this._ferTime_ComBoxCustomTime), vm.FerMonth, vm.MonthList);
- ListBoxScrollIntoView(this._ferTime_ComBoxCustomTime.Template.FindName("dayListBox", this._ferTime_ComBoxCustomTime), vm.FerDay, vm.DayList);
- ListBoxScrollIntoView(this._ferTime_ComBoxCustomTime.Template.FindName("hourListBox", this._ferTime_ComBoxCustomTime), vm.FerHour, vm.HourList);
- ListBoxScrollIntoView(this._ferTime_ComBoxCustomTime.Template.FindName("minListBox", this._ferTime_ComBoxCustomTime), vm.FerMin, vm.MinList);
- }
- private void ListBoxScrollIntoView(object listBoxObject, int selectItem, List<int> sourceList)
- {
- if (!(listBoxObject is ListBox listBox)) return;
- if (listBox == null) return;
- int i = sourceList.IndexOf(selectItem) + 1;
- if (i <= 0) i = 0;
- if (i >= sourceList.Count) i = (sourceList.Count - 1);
- listBox.ScrollIntoView(sourceList[i]);
- }
- private void _ferTime_ComBoxCustomTime_DropDownClosed(object sender, EventArgs e)
- {
- this._ferTime_ComBoxCustomTime.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D4D4D"));
- }
- private void Close_Click(object sender, RoutedEventArgs e)
- {
- this.DialogResult = false;
- }
- }
- }
|