AddDishWindowView.xaml.cs 34 KB

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