AddDishWindowView.xaml.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. using ivf_tl_Entity.DTO;
  2. using ivf_tl_Entity.GlobalEntitys;
  3. using ivf_tl_Entity.GlobalEnums;
  4. using ivf_tl_Operate.Converts;
  5. using ivf_tl_Operate.Windows;
  6. using Newtonsoft.Json;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Diagnostics;
  10. using System.Linq;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. namespace ivf_tl_Operate.View
  17. {
  18. /// <summary>
  19. /// AddDishWindowView.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class AddDishWindowView : Window
  22. {
  23. private double centerX, centerY;
  24. private int Count = 16;
  25. private double angle;
  26. private double angleOffset = 90;
  27. private double imageBigRadius = 450;
  28. private double imageRadius = 80;
  29. private double textBigRadius = 300;
  30. int ellipseCount = 16;
  31. List<Border> BorderList = new List<Border>();
  32. private string tlsn;
  33. private int housesn;
  34. private bool isBalacne = false;
  35. private long balanceId = 0;
  36. private ExDish ExDish = null;
  37. /// <summary>
  38. /// 新建患者
  39. /// </summary>
  40. /// <param name="housesn"></param>
  41. /// <param name="isBalacne"></param>
  42. /// <param name="balanceId"></param>
  43. /// <param name="exDish"></param>
  44. public AddDishWindowView(int housesn, bool isBalacne, long balanceId)
  45. {
  46. InitializeComponent();
  47. this.Owner = AppData.Instance.MainWindow;
  48. ApplyResponsiveSize(); // G2-1:按屏幕工作区等比缩放窗口,避免写死 1422×2500 超出屏幕被裁
  49. this.isBalacne = isBalacne;
  50. this.balanceId = balanceId;
  51. this.TextBlock_HouseSn.Text = housesn.ToString();
  52. if (isBalacne)
  53. {
  54. //this._balance_Button.Content = "结束平衡";
  55. this._balance_Button.Content = KeyToStringConvert.GetLanguageStringByKey("C0029");
  56. }
  57. this.tlsn = AppData.Instance.TlSn;
  58. this.housesn = housesn;
  59. //this.numbertext.Text = $"新建患者信息";
  60. this.numbertext.Text = KeyToStringConvert.GetLanguageStringByKey("C0262");
  61. centerX = 1422 / 2.0;
  62. centerY = 1229 / 2.0;
  63. angle = 360.00 / 16;
  64. int curreYeat = DateTime.Now.Year;
  65. for (int i = 1963; i <= curreYeat; i++) YearsList.Add(i);
  66. for (int i = 1; i <= 12; i++) MonthList.Add(i);
  67. for (int i = 1; i <= 31; i++) DayList.Add(i);
  68. this._wifeYear.ItemsSource = YearsList;
  69. this._wifeMonth.ItemsSource = MonthList;
  70. this._wifeDay.ItemsSource = DayList;
  71. this._husbandYear.ItemsSource = YearsList;
  72. this._husbandMonth.ItemsSource = MonthList;
  73. this._husbandDay.ItemsSource = DayList;
  74. this._freType_ComboBox.ItemsSource = AppData.Instance.FertilizationTypeEntitieList;
  75. InitAddCustom();
  76. Closed += (a, b) => AppData.Instance.MainWindow.Activate();
  77. }
  78. /// <summary>
  79. /// G2-1:按屏幕工作区把设计基准 1422×2500 等比缩放为窗口实际尺寸(只缩不放),
  80. /// 配合 XAML 外层 Viewbox(Uniform),使弹窗在任意分辨率/竖屏下完整可见、居中、不溢出、不变形。
  81. /// </summary>
  82. private void ApplyResponsiveSize()
  83. {
  84. try
  85. {
  86. const double designW = 1422.0, designH = 2500.0;
  87. var wa = System.Windows.SystemParameters.WorkArea; // 去掉任务栏的可用区
  88. double margin = 0.96; // 四周留一点边距
  89. double scale = System.Math.Min(wa.Width * margin / designW, wa.Height * margin / designH);
  90. if (scale > 1.0) scale = 1.0; // 设计稿够大时不放大
  91. this.Width = designW * scale;
  92. this.Height = designH * scale;
  93. }
  94. catch { /* 兜底:保留 XAML 默认尺寸 */ }
  95. }
  96. /// <summary>
  97. /// 修改患者
  98. /// </summary>
  99. /// <param name="housesn"></param>
  100. /// <param name="exDish"></param>
  101. public AddDishWindowView(ExDish exDish, List<DishPicAndVideo> datas)
  102. {
  103. InitializeComponent();
  104. this.Owner = AppData.Instance.MainWindow;
  105. ApplyResponsiveSize(); // G2-1:按屏幕工作区等比缩放窗口,避免写死 1422×2500 超出屏幕被裁
  106. ExDish = exDish;
  107. this.TextBlock_HouseSn.Text = ExDish.houseSn.ToString();
  108. //this.numbertext.Text = $"编辑患者信息";
  109. this.numbertext.Text = KeyToStringConvert.GetLanguageStringByKey("C0263");
  110. centerX = 1422 / 2.0;
  111. centerY = 1229 / 2.0;
  112. angle = 360.00 / 16;
  113. int curreYeat = DateTime.Now.Year;
  114. for (int i = 1963; i <= curreYeat; i++) YearsList.Add(i);
  115. for (int i = 1; i <= 12; i++) MonthList.Add(i);
  116. for (int i = 1; i <= 31; i++) DayList.Add(i);
  117. this._wifeYear.ItemsSource = YearsList;
  118. this._wifeMonth.ItemsSource = MonthList;
  119. this._wifeDay.ItemsSource = DayList;
  120. this._husbandYear.ItemsSource = YearsList;
  121. this._husbandMonth.ItemsSource = MonthList;
  122. this._husbandDay.ItemsSource = DayList;
  123. this._freType_ComboBox.ItemsSource = AppData.Instance.FertilizationTypeEntitieList;
  124. InitEditCustom(datas);
  125. Closed += (a, b) => AppData.Instance.MainWindow.Activate();
  126. }
  127. List<int> YearsList = new List<int>();
  128. List<int> MonthList = new List<int>();
  129. List<int> DayList = new List<int>();
  130. private void InitAddCustom()
  131. {
  132. this._addDishButton.Visibility = Visibility.Visible;
  133. for (int i = 0; i < ellipseCount; i++)
  134. {
  135. TextBlock borderT = new TextBlock();
  136. Panel.SetZIndex(borderT, 7);
  137. this._canvas.Children.Add(borderT);
  138. borderT.Height = 28;
  139. borderT.Width = 35;
  140. borderT.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - borderT.Width / 2);
  141. borderT.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - borderT.Height / 2);
  142. borderT.Text = $"{i + 1}";
  143. borderT.TextAlignment = TextAlignment.Center;
  144. borderT.FontSize = 27;
  145. borderT.Foreground = new SolidColorBrush(Colors.Gray);
  146. Border border = new Border();
  147. this._canvas.Children.Add(border);
  148. BorderList.Add(border);
  149. border.Name = $"B{i + 1}";
  150. border.CornerRadius = new CornerRadius(imageRadius);
  151. border.Background = new SolidColorBrush(Colors.Red);
  152. Panel.SetZIndex(border, 9);
  153. border.Tag = false;
  154. border.Width = imageRadius * 2;
  155. border.Height = imageRadius * 2;
  156. border.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - border.Width / 2);
  157. border.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - border.Height / 2);
  158. border.SetValue(Panel.ZIndexProperty, 9);
  159. border.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Image/ellipse_backgroud.png", UriKind.RelativeOrAbsolute)));
  160. border.MouseUp += (s, e) =>
  161. {
  162. if (!(s is Border so)) return;
  163. var newTag = !(bool)so.Tag;
  164. if (newTag)
  165. {
  166. so.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Image/photo_embryo.png", UriKind.RelativeOrAbsolute)));
  167. }
  168. else
  169. {
  170. so.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Image/ellipse_backgroud.png", UriKind.RelativeOrAbsolute)));
  171. }
  172. so.Tag = newTag;
  173. };
  174. }
  175. if (this._freType_ComboBox.HasItems)
  176. {
  177. this._freType_ComboBox.SelectedIndex = 0;
  178. }
  179. }
  180. private void InitEditCustom(List<DishPicAndVideo> datas)
  181. {
  182. this._editDishButton.Visibility = Visibility.Visible;
  183. this._caseId_TextBox.IsEnabled = false;
  184. this._freType_ComboBox.IsEnabled = false;
  185. this._Border_TextBox.IsEnabled = false;
  186. this._cycle_TextBox.IsEnabled = false;
  187. this._Border_TextBox.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E4E4E4"));
  188. this._Border_TextBox.BorderBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#D1D1D1"));
  189. this._startTime_TextBox.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#A4A4A4"));
  190. this._caseId_TextBox.Text = ExDish.caseId;
  191. this._wife_TextBox.Text = ExDish.wife;
  192. this._cycle_TextBox.Text = ExDish.cycle;
  193. this._isVip.IsChecked = ExDish.vip == 1 ? true : false;
  194. if (DateTime.TryParse(ExDish.wifeBirth, out DateTime wifeTime))
  195. {
  196. this._wifeYear.SelectedItem = wifeTime.Year;
  197. this._wifeMonth.SelectedItem = wifeTime.Month;
  198. this._wifeDay.SelectedItem = wifeTime.Day;
  199. }
  200. this._husband_TextBox.Text = ExDish.husband;
  201. if (DateTime.TryParse(ExDish.husbandBirth, out DateTime husTime))
  202. {
  203. this._husbandYear.SelectedItem = husTime.Year;
  204. this._husbandMonth.SelectedItem = husTime.Month;
  205. this._husbandDay.SelectedItem = husTime.Day;
  206. }
  207. this._startTime_TextBox.Text = ExDish.startTime;
  208. int k = -1;
  209. for (int i = 0; i < AppData.Instance.FertilizationTypeEntitieList.Count; i++)
  210. {
  211. if (AppData.Instance.FertilizationTypeEntitieList[i].dictKey == ExDish.fertilizationType)
  212. {
  213. k = i;
  214. break;
  215. }
  216. }
  217. if (k != -1) this._freType_ComboBox.SelectedIndex = k;
  218. ExEmbryo exEmbryo = null;
  219. for (int i = 0; i < ellipseCount; i++)
  220. {
  221. exEmbryo = ExDish.embryoList.FirstOrDefault(x => x.wellSn == (i + 1));
  222. TextBlock borderT = new TextBlock();
  223. Panel.SetZIndex(borderT, 7);
  224. this._canvas.Children.Add(borderT);
  225. borderT.Height = 28;
  226. borderT.Width = 35;
  227. borderT.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - borderT.Width / 2);
  228. borderT.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * textBigRadius - borderT.Height / 2);
  229. borderT.Text = $"{i + 1}";
  230. borderT.TextAlignment = TextAlignment.Center;
  231. borderT.FontSize = 27;
  232. borderT.Foreground = new SolidColorBrush(Colors.Gray);
  233. Border border = new Border();
  234. this._canvas.Children.Add(border);
  235. BorderList.Add(border);
  236. border.Name = $"B{i + 1}";
  237. border.CornerRadius = new CornerRadius(imageRadius);
  238. border.Background = new SolidColorBrush(Colors.Red);
  239. Panel.SetZIndex(border, 9);
  240. border.Tag = false;
  241. border.Width = imageRadius * 2;
  242. border.Height = imageRadius * 2;
  243. border.SetValue(Canvas.LeftProperty, centerX + Math.Cos(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - border.Width / 2);
  244. border.SetValue(Canvas.TopProperty, centerY + Math.Sin(((angle * i + angleOffset) * (Math.PI)) / 180) * imageBigRadius - border.Height / 2);
  245. border.SetValue(Panel.ZIndexProperty, 9);
  246. border.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Image/ellipse_backgroud.png", UriKind.RelativeOrAbsolute)));
  247. if (exEmbryo == null)
  248. {
  249. border.MouseUp += (s, e) =>
  250. {
  251. if (!(s is Border so)) return;
  252. var newTag = !(bool)so.Tag;
  253. if (newTag)
  254. {
  255. so.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Image/photo_embryo.png", UriKind.RelativeOrAbsolute)));
  256. }
  257. else
  258. {
  259. so.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Image/ellipse_backgroud.png", UriKind.RelativeOrAbsolute)));
  260. }
  261. so.Tag = newTag;
  262. };
  263. }
  264. else
  265. {
  266. border.Tag = true;
  267. var currentData = datas.FirstOrDefault(x => x.wellSn == exEmbryo.wellSn);
  268. if (currentData != null && !string.IsNullOrEmpty(currentData.lastPicture))
  269. {
  270. string imageurl = $"{AppData.Instance.BaseUrl}{currentData.lastPicture.Replace(AppData.Instance.PicSuf, $"_160x160{AppData.Instance.PicSuf}")}?token={AppData.Instance.HttpHelper.GetToken()}";
  271. border.Background = new ImageBrush(AppData.Instance.ConvertHelper.StringToBitmapImage(imageurl));
  272. }
  273. else
  274. {
  275. border.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Image/photo_embryo.png", UriKind.RelativeOrAbsolute)));
  276. }
  277. }
  278. }
  279. }
  280. /// <summary>
  281. /// 修改培养
  282. /// </summary>
  283. /// <param name="sender"></param>
  284. /// <param name="e"></param>
  285. private void EditDishSave_Click(object sender, RoutedEventArgs e)
  286. {
  287. // M8-G3-1:命令入口埋点(module=皿管理)。
  288. using var _op = Aivfo.OperationLog.OperationLogger.Begin("皿管理", "保存/编辑皿信息");
  289. _op.Input(new { dishId = ExDish?.id, houseSn = ExDish?.houseSn, caseId = ExDish?.caseId });
  290. try
  291. {
  292. List<int> wellList = new List<int>();
  293. foreach (var item in BorderList)
  294. {
  295. if ((bool)item.Tag == true)
  296. {
  297. string borderName = item.Name;
  298. string number = borderName.Substring(1);
  299. if (int.TryParse(number, out int result))
  300. {
  301. wellList.Add(result);
  302. }
  303. }
  304. }
  305. string caseIdString = this._caseId_TextBox.Text.Trim();
  306. if (string.IsNullOrEmpty(caseIdString))
  307. {
  308. _op.Fail("校验失败:病例编号为空"); // M8-G3-1
  309. //MessageInfo("请输入病例编号");
  310. MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0148"));
  311. return;
  312. }
  313. string cycleIdString = this._cycle_TextBox.Text.Trim();
  314. if (string.IsNullOrEmpty(cycleIdString))
  315. {
  316. _op.Fail("校验失败:周期编号为空"); // M8-G3-1
  317. //MessageInfo("请输入周期编号");
  318. MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0316"));
  319. return;
  320. }
  321. string wifeString = this._wife_TextBox.Text.Trim();
  322. if (string.IsNullOrEmpty(wifeString))
  323. {
  324. _op.Fail("校验失败:女方姓名为空"); // M8-G3-1
  325. //MessageInfo("请输入女方姓名");
  326. MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0149"));
  327. return;
  328. }
  329. //if (wifeString.Length > 100)
  330. //{
  331. // MessageInfo("女方姓名字符长度为1-100");
  332. // return;
  333. //}
  334. string wifeBirthString = this._wifeAge.Text.Trim();
  335. if (string.IsNullOrEmpty(wifeBirthString))
  336. {
  337. wifeBirthString = null;
  338. //MessageInfo("请输入女方年龄");
  339. //return;
  340. }
  341. else
  342. {
  343. if (DateTime.TryParse($"{this._wifeYear.SelectedItem}-{this._wifeMonth.SelectedItem}-{this._wifeDay.SelectedItem}", out DateTime wifeTime)) wifeBirthString = wifeTime.ToString("yyyy-MM-dd HH:mm:ss");
  344. else
  345. {
  346. _op.Fail("校验失败:女方年龄错误"); // M8-G3-1
  347. MessageInfo("女方年龄错误");
  348. return;
  349. }
  350. }
  351. string husbandString = this._husband_TextBox.Text.Trim();
  352. if (string.IsNullOrEmpty(husbandString))
  353. {
  354. _op.Fail("校验失败:男方姓名为空"); // M8-G3-1
  355. //MessageInfo("请输入男方姓名");
  356. MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0150"));
  357. return;
  358. }
  359. //if (husbandString.Length > 100)
  360. //{
  361. // MessageInfo("男方姓名字符长度为1-100");
  362. // return;
  363. //}
  364. string husbandBirthString = this._husbandAge.Text.Trim();
  365. if (string.IsNullOrEmpty(husbandBirthString))
  366. {
  367. husbandBirthString = null;
  368. //MessageInfo("请输入男方年龄");
  369. //return;
  370. }
  371. else
  372. {
  373. if (DateTime.TryParse($"{this._husbandYear.SelectedItem}-{this._husbandMonth.SelectedItem}-{(int)this._husbandDay.SelectedItem}", out DateTime husTime)) husbandBirthString = husTime.ToString("yyyy-MM-dd HH:mm:ss");
  374. else
  375. {
  376. _op.Fail("校验失败:男方年龄错误"); // M8-G3-1
  377. MessageInfo("男方年龄错误");
  378. return;
  379. }
  380. }
  381. //ExDish.caseId = caseIdString;
  382. ExDish.wife = wifeString;
  383. ExDish.wifeBirth = wifeBirthString;
  384. ExDish.husbandBirth = husbandBirthString;
  385. ExDish.husband = husbandString;
  386. ExDish.vip = this._isVip.IsChecked == true ? 1 : 0;
  387. ExDish.embryoCount = wellList.Count;
  388. ExDish.cycle = cycleIdString;
  389. string body = JsonConvert.SerializeObject(new
  390. {
  391. embryoCount = ExDish.embryoCount,
  392. husband = ExDish.husband,
  393. husbandBirth = ExDish.husbandBirth,
  394. id = ExDish.id,
  395. vip = ExDish.vip,
  396. wellSn = wellList,
  397. wife = ExDish.wife,
  398. wifeBirth = ExDish.wifeBirth,
  399. cycle = ExDish.cycle,
  400. });
  401. if (!AppData.Instance.HttpHelper.UpdateDishInfoApi(body))
  402. {
  403. _op.Fail("修改皿信息接口返回失败"); // M8-G3-1
  404. //MessageInfo("修改信息失败");
  405. MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0243"));
  406. }
  407. else
  408. {
  409. _op.Success(); // M8-G3-1
  410. this.DialogResult = true;
  411. }
  412. }
  413. catch (Exception ex)
  414. {
  415. _op.Fail(ex.GetType().Name + ": " + ex.Message); // M8-G3-1
  416. AppData.Instance.LogHelper.ExceptionLog(ex, "AddDishWindowView.EditDishSave_Click", LogEnum.RunException);
  417. }
  418. }
  419. /// <summary>
  420. /// 开始培养
  421. /// </summary>
  422. /// <param name="sender"></param>
  423. /// <param name="e"></param>
  424. private void StartDish_Click(object sender, RoutedEventArgs e)
  425. {
  426. // M8-G3-1:命令入口埋点(module=皿管理)。
  427. using var _op = Aivfo.OperationLog.OperationLogger.Begin("皿管理", "启动培养皿");
  428. _op.Input(new { houseSn = housesn, tlSn = tlsn });
  429. try
  430. {
  431. List<int> wellList = new List<int>();
  432. foreach (var item in BorderList)
  433. {
  434. if ((bool)item.Tag == true)
  435. {
  436. string borderName = item.Name;
  437. string number = borderName.Substring(1);
  438. if (int.TryParse(number, out int result)) wellList.Add(result);
  439. }
  440. }
  441. if (!wellList.Any())
  442. {
  443. _op.Fail("校验失败:未选择胚胎孔位"); // M8-G3-1
  444. //MessageInfo("请选择胚胎孔位");
  445. MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0317"));
  446. return;
  447. }
  448. string caseIdString = this._caseId_TextBox.Text.Trim();
  449. if (string.IsNullOrEmpty(caseIdString))
  450. {
  451. _op.Fail("校验失败:病例编号为空"); // M8-G3-1
  452. //MessageInfo("请输入病例编号");
  453. MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0148"));
  454. return;
  455. }
  456. string cycleIdString = this._cycle_TextBox.Text.Trim();
  457. if (string.IsNullOrEmpty(cycleIdString))
  458. {
  459. _op.Fail("校验失败:周期编号为空"); // M8-G3-1
  460. //MessageInfo("请输入周期编号");
  461. MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0316"));
  462. return;
  463. }
  464. string wifeString = this._wife_TextBox.Text.Trim();
  465. if (string.IsNullOrEmpty(wifeString))
  466. {
  467. _op.Fail("校验失败:女方姓名为空"); // M8-G3-1
  468. //MessageInfo("请输入女方姓名");
  469. MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0149"));
  470. return;
  471. }
  472. //if (wifeString.Length > 100)
  473. //{
  474. // MessageInfo("女方姓名字符长度为1-100");
  475. // return;
  476. //}
  477. string wifeBirthString = this._wifeAge.Text.Trim();
  478. if (string.IsNullOrEmpty(wifeBirthString))
  479. {
  480. wifeBirthString = null;
  481. //MessageInfo("请输入女方年龄");
  482. //return;
  483. }
  484. else
  485. {
  486. if (DateTime.TryParse($"{this._wifeYear.SelectedItem}-{this._wifeMonth.SelectedItem}-{this._wifeDay.SelectedItem}", out DateTime wifeTime)) wifeBirthString = wifeTime.ToString("yyyy-MM-dd HH:mm:ss");
  487. else
  488. {
  489. _op.Fail("校验失败:女方年龄错误"); // M8-G3-1
  490. MessageInfo("女方年龄错误");
  491. return;
  492. }
  493. }
  494. string husbandString = this._husband_TextBox.Text.Trim();
  495. if (string.IsNullOrEmpty(husbandString))
  496. {
  497. _op.Fail("校验失败:男方姓名为空"); // M8-G3-1
  498. //MessageInfo("请输入男方姓名");
  499. MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0150"));
  500. return;
  501. }
  502. //if (husbandString.Length > 100)
  503. //{
  504. // MessageInfo("男方姓名字符长度为1-100");
  505. // return;
  506. //}
  507. string husbandBirthString = this._husbandAge.Text.Trim();
  508. if (string.IsNullOrEmpty(husbandBirthString))
  509. {
  510. husbandBirthString = null;
  511. //MessageInfo("请输入男方年龄");
  512. //return;
  513. }
  514. else
  515. {
  516. if (DateTime.TryParse($"{this._husbandYear.SelectedItem}-{this._husbandMonth.SelectedItem}-{(int)this._husbandDay.SelectedItem}", out DateTime husTime)) husbandBirthString = husTime.ToString("yyyy-MM-dd HH:mm:ss");
  517. else
  518. {
  519. _op.Fail("校验失败:男方年龄错误"); // M8-G3-1
  520. MessageInfo("男方年龄错误");
  521. return;
  522. }
  523. }
  524. string startTimeString = this._startTime_TextBox.Text.Trim();
  525. if (string.IsNullOrEmpty(startTimeString))
  526. {
  527. _op.Fail("校验失败:受精时间为空"); // M8-G3-1
  528. //MessageInfo("请输入受精时间");
  529. MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0154"));
  530. return;
  531. }
  532. if (DateTime.TryParse(startTimeString, out DateTime result1))
  533. {
  534. if (result1 > DateTime.Now)
  535. {
  536. _op.Fail("校验失败:受精时间超过当前时间"); // M8-G3-1
  537. //MessageInfo("受精时间不能超过当前时间");
  538. MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0264"));
  539. return;
  540. }
  541. }
  542. else
  543. {
  544. _op.Fail("校验失败:受精时间输入错误"); // M8-G3-1
  545. //MessageInfo("受精时间输入错误");
  546. MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0154"));
  547. return;
  548. }
  549. //string cycleString = this._cycle_TextBox.Text.Trim();
  550. //string phoneString = this._phone_TextBox.Text.Trim();
  551. //if (string.IsNullOrEmpty(phoneString))
  552. //{
  553. // MessageInfo("请输入联系方式");
  554. // return;
  555. //}
  556. //if (!Regex.IsMatch(phoneString, @"^1[3456789]\d{9}$"))
  557. //{
  558. // MessageInfo("联系方式输入错误");
  559. // return;
  560. //}
  561. ExDish exDish = new ExDish();
  562. exDish.tlSn = tlsn;
  563. exDish.houseSn = housesn;
  564. exDish.caseId = caseIdString;
  565. exDish.wife = wifeString;
  566. exDish.cycle = cycleIdString;
  567. exDish.wifeBirth = wifeBirthString;
  568. exDish.husbandBirth = husbandBirthString;
  569. exDish.husband = husbandString;
  570. exDish.vip = this._isVip.IsChecked == true ? 1 : 0;
  571. exDish.embryoCount = wellList.Count;
  572. exDish.startTime = startTimeString;
  573. if (this._freType_ComboBox.SelectedItem is FertilizationTypeEntity typeEntity)
  574. {
  575. exDish.fertilizationType = typeEntity.dictKey;
  576. exDish.fertilizationTypeId = int.Parse(typeEntity.dictValue);
  577. }
  578. //exDish.phone = phoneString;
  579. exDish.embryoCount = wellList.Count;
  580. exDish.wellSn = wellList;
  581. string error = AppData.Instance.HttpHelper.AddCultureRecordApi(exDish);
  582. if (!string.IsNullOrEmpty(error))
  583. {
  584. _op.Fail("启动培养皿接口返回失败:" + error); // M8-G3-1
  585. //MessageInfo($"开始培养失败:{error}");
  586. MessageInfo($"{KeyToStringConvert.GetLanguageStringByKey("C0265")}:{error}");
  587. }
  588. else
  589. {
  590. _op.Success(); // M8-G3-1
  591. this.DialogResult = true;
  592. }
  593. }
  594. catch (Exception ex)
  595. {
  596. _op.Fail(ex.GetType().Name + ": " + ex.Message); // M8-G3-1
  597. AppData.Instance.LogHelper.ExceptionLog(ex, "AddDishWindowView.StartDish_Click", LogEnum.RunException);
  598. }
  599. e.Handled = true;
  600. }
  601. /// <summary>
  602. /// 平衡操作
  603. /// </summary>
  604. /// <param name="sender"></param>
  605. /// <param name="e"></param>
  606. private void StartBalance_Click(object sender, RoutedEventArgs e)
  607. {
  608. //Debug.WriteLine("平衡按钮");
  609. // M8-G3-1:命令入口埋点(module=皿管理)。
  610. using var _op = Aivfo.OperationLog.OperationLogger.Begin("皿管理", isBalacne ? "结束平衡皿" : "启动平衡皿");
  611. _op.Input(new { houseSn = housesn, tlSn = tlsn, isBalance = isBalacne, balanceId = balanceId });
  612. if (isBalacne)//结束平衡
  613. {
  614. if (balanceId == 0)
  615. {
  616. _op.Fail("校验失败:获取平衡记录失败"); // M8-G3-1
  617. //MessageInfo("获取平衡记录失败");
  618. MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0266"));
  619. return;
  620. }
  621. if (AppData.Instance.HttpHelper.StopBalanceApi(balanceId))
  622. {
  623. _op.Success(); // M8-G3-1
  624. this.DialogResult = true;
  625. }
  626. else
  627. {
  628. _op.Fail("结束平衡接口返回失败"); // M8-G3-1
  629. //MessageInfo("结束平衡失败");
  630. MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0267"));
  631. }
  632. }
  633. else//开始平衡
  634. {
  635. if (AppData.Instance.HttpHelper.StartBalanceApi(housesn, tlsn))
  636. {
  637. _op.Success(); // M8-G3-1
  638. this.DialogResult = true;
  639. }
  640. else
  641. {
  642. _op.Fail("开始平衡接口返回失败"); // M8-G3-1
  643. //MessageInfo("开始平衡失败");
  644. MessageInfo(KeyToStringConvert.GetLanguageStringByKey("C0268"));
  645. }
  646. }
  647. }
  648. private void Cancel_Click(object sender, RoutedEventArgs e)
  649. {
  650. this.DialogResult = false;
  651. }
  652. private void Cancel_MouseUp(object sender, MouseButtonEventArgs e)
  653. {
  654. //MessageBox.Show("点击×");
  655. //int is1 = 1 + 1;
  656. //Debug.WriteLine("==============================================================");
  657. this.DialogResult = false;
  658. }
  659. private string GetDataTime()
  660. {
  661. try
  662. {
  663. this._mask.Visibility = Visibility.Visible;
  664. GetDateWindow getDate = new GetDateWindow(this);
  665. getDate._dateControl.SetNYR(false);
  666. getDate.isClos = false;
  667. var result = getDate.ShowDialog();
  668. if (result.Value == true)
  669. {
  670. return $"{getDate.Date}:00";
  671. }
  672. return null;
  673. }
  674. catch (Exception ex)
  675. {
  676. return null;
  677. }
  678. finally
  679. {
  680. this._mask.Visibility = Visibility.Hidden;
  681. }
  682. }
  683. private void StartTime_MouseUp(object sender, MouseButtonEventArgs e)
  684. {
  685. string newTime = GetDataTime();
  686. if (string.IsNullOrEmpty(newTime))
  687. {
  688. return;
  689. }
  690. this._startTime_TextBox.Text = newTime;
  691. this._startTime_TextBox.Foreground = new SolidColorBrush(Colors.Black);
  692. }
  693. private void WifeBirth_MouseUp(object sender, MouseButtonEventArgs e)
  694. {
  695. string newTime = GetDataTime();
  696. if (string.IsNullOrEmpty(newTime))
  697. {
  698. return;
  699. }
  700. //this._wifeBirth_TextBox.Text = newTime;
  701. }
  702. private void HusbandBirth_MouseUp(object sender, MouseButtonEventArgs e)
  703. {
  704. string newTime = GetDataTime();
  705. if (string.IsNullOrEmpty(newTime))
  706. {
  707. return;
  708. }
  709. //this._husbandBirth_TextBox.Text = newTime;
  710. }
  711. private void Wifi_SelectionChanged(object sender, SelectionChangedEventArgs e)
  712. {
  713. if (this._wifeYear.SelectedItem != null && this._wifeMonth.SelectedItem != null && this._wifeDay.SelectedItem != null)
  714. {
  715. int CurrentYear = (int)this._wifeYear.SelectedItem;
  716. int CurrentMonth = (int)this._wifeMonth.SelectedItem;
  717. int CurrentDay = (int)this._wifeDay.SelectedItem;
  718. int age = DateTime.Now.Year - CurrentYear;
  719. if (DateTime.Now.Month < CurrentMonth || (DateTime.Now.Month == CurrentMonth && DateTime.Now.Day < CurrentDay)) age--;
  720. this._wifeAge.Text = age.ToString();
  721. }
  722. }
  723. private void HusBand_SelectionChanged(object sender, SelectionChangedEventArgs e)
  724. {
  725. if (this._husbandYear.SelectedItem != null && this._husbandMonth.SelectedItem != null && this._husbandDay.SelectedItem != null)
  726. {
  727. int CurrentYear = (int)this._husbandYear.SelectedItem;
  728. int CurrentMonth = (int)this._husbandMonth.SelectedItem;
  729. int CurrentDay = (int)this._husbandDay.SelectedItem;
  730. int age = DateTime.Now.Year - CurrentYear;
  731. if (DateTime.Now.Month < CurrentMonth || (DateTime.Now.Month == CurrentMonth && DateTime.Now.Day < CurrentDay)) age--;
  732. this._husbandAge.Text = age.ToString();
  733. }
  734. }
  735. private void Border_MouseUp(object sender, MouseButtonEventArgs e)
  736. {
  737. //MessageBox.Show("点击生效");
  738. int kk = 1 + 1;
  739. }
  740. private void Grid_PreviewTouchDown(object sender, TouchEventArgs e)
  741. {
  742. //Debug.WriteLine("===================ImageTouchDown===========================================");
  743. }
  744. private void MessageInfo(string mess)
  745. {
  746. this._errorInfo_TextBlock.Text = mess;
  747. }
  748. }
  749. }