AddDishWindow.xaml.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. using ivf_tl_Entity.Entity.balance;
  2. using ivf_tl_Entity.Enums;
  3. using ivf_tl_Manage.Converts;
  4. using ivf_tl_Manage.ViewModels.Win;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. namespace ivf_tl_Manage.Win
  13. {
  14. /// <summary>
  15. /// AddDishWindow.xaml 的交互逻辑
  16. /// </summary>
  17. public partial class AddDishWindow : Window
  18. {
  19. public AddDishWindowViewModel vm = null;
  20. private Balance currentBalance { get; set; }
  21. public AddDishWindow(Dish dish, Balance balance, Window w)
  22. {
  23. InitializeComponent();
  24. this.Owner = w;
  25. centerX = 352 / 2.0;
  26. centerY = 362 / 2.0;
  27. angle = 360.00 / 16;
  28. vm = new AddDishWindowViewModel(dish);
  29. currentBalance = balance;
  30. this.DataContext = vm;
  31. InitCustom();
  32. }
  33. private Dictionary<int, Image> EmbryoStateImageList = new Dictionary<int, Image>();
  34. private double centerX, centerY;
  35. private double angle;
  36. private double angleOffset = 90;
  37. private int ellipseCount = 16;
  38. private int imageRadius = 22;
  39. //115
  40. private int imageBigRadius = 120;
  41. //65
  42. private int textRadius = 93;
  43. private void InitCustom()
  44. {
  45. try
  46. {
  47. //List<PictureEntity> picList = new List<PictureEntity>();
  48. //if (vm.CurrentDish != null && vm.CurrentDish.id > 0)
  49. //{
  50. // var pro = AppData.Instance.GetDishProvider();
  51. // var wellIdList = vm.CurrentDish.embryoList.Select(x => x.id).ToList();
  52. // if (wellIdList.Any())
  53. // {
  54. // picList = pro.GetNewPicApi(vm.CurrentDish.tlSn, vm.CurrentDish.houseSn, wellIdList);
  55. // }
  56. //}
  57. int currentWell = 1;
  58. //EllipseGeometry ellipseGeometry = new EllipseGeometry(new Point(imageRadius-2, imageRadius-2), imageRadius-2, imageRadius-2);
  59. for (int i = 0; i < ellipseCount; i++)
  60. {
  61. currentWell = i + 1;
  62. TextBlock textBlock = new TextBlock();
  63. Image border = new Image();
  64. textBlock.Text = $"{currentWell}";
  65. textBlock.TextAlignment = TextAlignment.Center;
  66. textBlock.FontWeight = FontWeights.Medium;
  67. textBlock.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9B9B9B"));
  68. //textBlock.Foreground = new SolidColorBrush(Colors.Red);
  69. //textBlock.Background = new SolidColorBrush(Colors.LightBlue);
  70. textBlock.FontSize = 10;
  71. textBlock.Width = 12;
  72. textBlock.Height = 14;
  73. textBlock.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * textRadius - 6);
  74. textBlock.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * textRadius - 7);
  75. Panel.SetZIndex(textBlock, 7);
  76. Panel.SetZIndex(border, 6);
  77. this._canvas.Children.Add(textBlock);
  78. this._canvas.Children.Add(border);
  79. border.Name = $"B{currentWell}";
  80. EmbryoStateImageList.Add(currentWell, border);
  81. border.Width = imageRadius * 2;
  82. border.Height = imageRadius * 2;
  83. border.Tag = false;
  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. var embryo = vm.CurrentDish.embryoList.FirstOrDefault(a => a.wellSn == currentWell);
  87. if (embryo == null)
  88. {
  89. border.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/NoEmbryoYuanIcon.png", UriKind.Absolute));
  90. border.MouseUp += (s, e) =>
  91. {
  92. var sender = s as Image;
  93. sender.Tag = !(bool)sender.Tag;
  94. if ((bool)sender.Tag == true) border.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EditEmbryoSelectedIcon.png", UriKind.Absolute));
  95. else border.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/NoEmbryoYuanIcon.png", UriKind.Absolute));
  96. if (vm.CurrentDish.id > 0) return;
  97. if (EmbryoStateImageList.FirstOrDefault(x => (bool)x.Value.Tag).Value == null)
  98. vm.IsEmbryo = 0;
  99. else vm.IsEmbryo = 1;
  100. };
  101. }
  102. else
  103. {
  104. string imageUrl = null;
  105. //var currentPic= picList.FirstOrDefault(x => x.wellSn == embryo.wellSn);
  106. //if (currentPic != null) imageUrl = $"{AppData.Instance.BaseUrl}{currentPic.imageUrl}?token={AppData.Instance.HttpServiceCall.GetToken()}";
  107. //if(imageUrl != null)
  108. //{
  109. // border.Source = new BitmapImage(new Uri(imageUrl, UriKind.Absolute));
  110. // border.SetValue(Image.ClipProperty, ellipseGeometry);
  111. // continue;
  112. //}
  113. EmbryoState state = (EmbryoState)embryo.state;
  114. switch (state)
  115. {
  116. case EmbryoState.None:
  117. imageUrl= "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoYuanIcon.png";
  118. break;
  119. case EmbryoState.Freezing://冷冻
  120. imageUrl = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoFreezingIcon.png";
  121. break;
  122. case EmbryoState.Transplant://移植
  123. imageUrl = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoTransplantIcon.png";
  124. break;
  125. case EmbryoState.Cancellation://作废
  126. imageUrl = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoCancellationIcon.png";
  127. break;
  128. case EmbryoState.Delete://删除
  129. imageUrl = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoDeleteIcon.png";
  130. break;
  131. default:
  132. imageUrl = "pack://application:,,,/ivf_tl_Manage;component/Resources/Images/EmbryoYuanIcon.png";
  133. break;
  134. }
  135. border.Source = new BitmapImage(new Uri(imageUrl, UriKind.Absolute));
  136. }
  137. }
  138. if (vm.CurrentDish != null && vm.CurrentDish.id > 0)
  139. {
  140. this._balance_Button.Visibility = Visibility.Hidden;
  141. return;
  142. }
  143. if (currentBalance != null && currentBalance.id > 0)
  144. {
  145. this._balanceStop_Button.Visibility = Visibility.Visible;
  146. return;
  147. }
  148. this._balance_Button.Visibility = Visibility.Visible;
  149. }
  150. catch (Exception)
  151. {
  152. }
  153. }
  154. private void ExLog(Exception ex, string name)
  155. {
  156. AppData.Instance.LogService.ExceptionLog(ex, $"AddDishWindow.{name}", LogEnum.RunException);
  157. }
  158. private void ErrorLog(string message, LogEnum logType)
  159. {
  160. AppData.Instance.LogService.TLLog($"AddDishWindow.{message}", logType);
  161. }
  162. private void DefeatMessage(string message)
  163. {
  164. this._message.Text = message;
  165. }
  166. private void Ok_Click(object sender, RoutedEventArgs e)
  167. {
  168. this.DialogResult = false;
  169. }
  170. private void StartBalance_Click(object sender, RoutedEventArgs e)
  171. {
  172. if (vm == null) return;
  173. var error = vm.StartBalance();
  174. if (string.IsNullOrEmpty(error))
  175. {
  176. this.DialogResult = true;
  177. return;
  178. }
  179. //DefeatMessage($"开启平衡失败:{error}");
  180. DefeatMessage($"{KeyToStringConvert.GetLanguageStringByKey("0313")}:{error}");
  181. }
  182. private void StopBalance_Click(object sender, RoutedEventArgs e)
  183. {
  184. if (vm == null || currentBalance == null) return;
  185. if (currentBalance.id <= 0) return;
  186. var error = vm.StopBalance(currentBalance.id);
  187. if (string.IsNullOrEmpty(error))
  188. {
  189. this.DialogResult = true;
  190. return;
  191. }
  192. //DefeatMessage($"结束平衡失败:{error}");
  193. DefeatMessage($"{KeyToStringConvert.GetLanguageStringByKey("0314")}:{error}");
  194. }
  195. private void StartDish_Click(object sender, RoutedEventArgs e)
  196. {
  197. //MessageBox.Show($"{vm.FerYear}-{vm.FerMonth}-{vm.FerDay} {vm.FerHour}:{vm.FerMin}");
  198. //return;
  199. //Thread.Sleep(1000 * 5);
  200. if (vm.CurrentDish.wife.Length > 100 || vm.CurrentDish.husband.Length > 100)
  201. {
  202. //DefeatMessage("姓名长度不能超过100个字符");
  203. DefeatMessage(KeyToStringConvert.GetLanguageStringByKey("0315"));
  204. return;
  205. }
  206. List<int> newWellSnList = null;
  207. if (vm.CurrentDish.id == 0 && vm.IsEmbryo == 0)
  208. {
  209. //DefeatMessage("未选择胚胎");
  210. DefeatMessage(KeyToStringConvert.GetLanguageStringByKey("0303"));
  211. return;
  212. }
  213. newWellSnList = EmbryoStateImageList.Where(x => (bool)x.Value.Tag).Select(x => x.Key).ToList();
  214. if (vm.CurrentDish.id == 0)
  215. {
  216. string startDishResult = vm.StartDish(newWellSnList);
  217. if (!string.IsNullOrEmpty(startDishResult))
  218. {
  219. DefeatMessage(startDishResult);
  220. return;
  221. }
  222. this.DialogResult = true;
  223. return;
  224. }
  225. foreach (var item in vm.CurrentDish.embryoList)
  226. {
  227. newWellSnList.Add(item.wellSn);
  228. }
  229. string updateResult = vm.UpdateDish(newWellSnList);
  230. if (!string.IsNullOrEmpty(updateResult))
  231. {
  232. DefeatMessage(updateResult);
  233. return;
  234. }
  235. this.DialogResult = true;
  236. return;
  237. }
  238. bool isOneOpen = false;
  239. private void ComBoxCustomTime_DropDownOpened(object sender, EventArgs e)
  240. {
  241. if (isOneOpen) return;
  242. isOneOpen = true;
  243. if (vm.CurrentDish.id == 0)
  244. {
  245. var dateNow = DateTime.Now;
  246. vm.FerYear = dateNow.Year;
  247. vm.FerMonth = dateNow.Month;
  248. vm.FerDay = dateNow.Day;
  249. vm.FerHour = dateNow.Hour;
  250. vm.FerMin = dateNow.Minute;
  251. }
  252. ListBoxScrollIntoView(this._ferTime_ComBoxCustomTime.Template.FindName("yearListBox", this._ferTime_ComBoxCustomTime), vm.FerYear, vm.YearsList);
  253. ListBoxScrollIntoView(this._ferTime_ComBoxCustomTime.Template.FindName("monthListBox", this._ferTime_ComBoxCustomTime), vm.FerMonth, vm.MonthList);
  254. ListBoxScrollIntoView(this._ferTime_ComBoxCustomTime.Template.FindName("dayListBox", this._ferTime_ComBoxCustomTime), vm.FerDay, vm.DayList);
  255. ListBoxScrollIntoView(this._ferTime_ComBoxCustomTime.Template.FindName("hourListBox", this._ferTime_ComBoxCustomTime), vm.FerHour, vm.HourList);
  256. ListBoxScrollIntoView(this._ferTime_ComBoxCustomTime.Template.FindName("minListBox", this._ferTime_ComBoxCustomTime), vm.FerMin, vm.MinList);
  257. }
  258. private void ListBoxScrollIntoView(object listBoxObject, int selectItem, List<int> sourceList)
  259. {
  260. if (!(listBoxObject is ListBox listBox)) return;
  261. if (listBox == null) return;
  262. int i = sourceList.IndexOf(selectItem) + 1;
  263. if (i <= 0) i = 0;
  264. if (i >= sourceList.Count) i = (sourceList.Count - 1);
  265. listBox.ScrollIntoView(sourceList[i]);
  266. }
  267. private void _ferTime_ComBoxCustomTime_DropDownClosed(object sender, EventArgs e)
  268. {
  269. this._ferTime_ComBoxCustomTime.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D4D4D"));
  270. }
  271. private void Close_Click(object sender, RoutedEventArgs e)
  272. {
  273. this.DialogResult = false;
  274. }
  275. }
  276. }