MarkLevelWindow.xaml.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using ivf_tl_Entity.Entity.Mark;
  2. using ivf_tl_Entity.Enums;
  3. using ivf_tl_Manage.Converts;
  4. using Newtonsoft.Json;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Shapes;
  18. namespace ivf_tl_Manage.Win
  19. {
  20. /// <summary>
  21. /// MarkLevelWindow.xaml 的交互逻辑
  22. /// </summary>
  23. public partial class MarkLevelWindow : Window
  24. {
  25. private bool isAdd = true;
  26. private MarkLevelEntity markLevel = null;
  27. public MarkLevelWindow(MarkLevelEntity markLevelEntity)
  28. {
  29. try
  30. {
  31. InitializeComponent();
  32. this.Owner = AppData.Instance.MainWindow;
  33. markLevel = markLevelEntity;
  34. this.Closed += (a, b) => AppData.Instance.MainWindow.Activate();
  35. }
  36. catch (Exception ex)
  37. {
  38. ExLog(ex, "MarkLevelWindow");
  39. }
  40. }
  41. public MarkLevelWindow(MarkLevelEntity markLevelEntity, bool b)
  42. {
  43. try
  44. {
  45. InitializeComponent();
  46. this.Owner = AppData.Instance.MainWindow;
  47. isAdd = false;
  48. markLevel = markLevelEntity;
  49. //this._title_TextBlock.Text = "编辑";
  50. this._title_TextBlock.Text = KeyToStringConvert.GetLanguageStringByKey("0083");
  51. this._name_TextBox.Text = markLevel.name;
  52. this._min_TextBox.Text = markLevel.min.ToString();
  53. this._max_TextBox.Text = markLevel.max.ToString();
  54. this.Closed += (a, b) => AppData.Instance.MainWindow.Activate();
  55. }
  56. catch (Exception ex)
  57. {
  58. ExLog(ex, "MarkLevelWindow");
  59. }
  60. }
  61. private void Cancel_Click(object sender, RoutedEventArgs e)
  62. {
  63. this.DialogResult = false;
  64. return;
  65. }
  66. private void Ok_Click(object sender, RoutedEventArgs e)
  67. {
  68. try
  69. {
  70. string nameString = this._name_TextBox.Text.Trim();
  71. if (string.IsNullOrEmpty(nameString))
  72. {
  73. //MessageBoxShow("级别名称不能为空");
  74. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0229"));
  75. return;
  76. }
  77. if(nameString.Length > 10)
  78. {
  79. //MessageBoxShow("级别名称长度为1-10");
  80. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0229"));
  81. return;
  82. }
  83. if(int.TryParse(this._min_TextBox.Text.Trim(), out int newMinTime) && newMinTime > 0)
  84. {
  85. }
  86. else
  87. {
  88. //MessageBoxShow("最小范围只能输入大于0的数字");
  89. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0294"));
  90. return;
  91. }
  92. if (int.TryParse(this._max_TextBox.Text.Trim(), out int newMaxTime) && newMaxTime > 0)
  93. {
  94. }
  95. else
  96. {
  97. //MessageBoxShow("最大范围只能输入大于0的数字");
  98. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0295"));
  99. return;
  100. }
  101. if (newMaxTime < newMinTime)
  102. {
  103. //MessageBoxShow("最大范围不能小于最小范围");
  104. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0296"));
  105. return;
  106. }
  107. string remakr = this._remake_TextBox.Text.Trim();
  108. MarkLevelEntity newLevel = new MarkLevelEntity();
  109. newLevel.name = nameString;
  110. newLevel.min = newMinTime;
  111. newLevel.max = newMaxTime;
  112. newLevel.id = markLevel.id;
  113. newLevel.info = remakr;
  114. var pro = AppData.Instance.GetMarkSettingProvider();
  115. string error = null;
  116. if (isAdd) error = pro.AddMarkLevelApi(newLevel);
  117. else error = pro.UpdateMarkLevelApi(JsonConvert.SerializeObject(newLevel));
  118. if (!string.IsNullOrEmpty(error))
  119. {
  120. //MessageBoxShow($"操作失败,{error}");
  121. MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0286")},{error}");
  122. return;
  123. }
  124. markLevel.id = newLevel.id;
  125. markLevel.name = nameString;
  126. markLevel.min = newMinTime;
  127. markLevel.max = newMaxTime;
  128. markLevel.info= remakr;
  129. this.DialogResult = true;
  130. return;
  131. }
  132. catch (Exception ex)
  133. {
  134. ExLog(ex, "Ok_Click");
  135. MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0291")},{ex.Message}");
  136. }
  137. }
  138. private void MessageBoxShow(string mess)
  139. {
  140. this.message.Text = mess;
  141. }
  142. private void ExLog(Exception ex, string name)
  143. {
  144. AppData.Instance.LogService.ExceptionLog(ex, $"MarkUseView.{name}", LogEnum.RunException);
  145. }
  146. private void ErrorLog(string message, LogEnum logType)
  147. {
  148. AppData.Instance.LogService.TLLog($"MarkUseView.{message}", logType);
  149. }
  150. private void Cancel_MouseUp(object sender, MouseButtonEventArgs e)
  151. {
  152. this.DialogResult = false;
  153. return;
  154. }
  155. }
  156. }