MarkModelWindow.xaml.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. using ivf_tl_Entity.Entity;
  2. using ivf_tl_Entity.Entity.Mark;
  3. using ivf_tl_Entity.Enums;
  4. using ivf_tl_Entity.Response;
  5. using ivf_tl_Manage.Converts;
  6. using Newtonsoft.Json;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Data;
  16. using System.Windows.Documents;
  17. using System.Windows.Input;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. using System.Windows.Shapes;
  21. namespace ivf_tl_Manage.Win
  22. {
  23. /// <summary>
  24. /// MarkModelWindow.xaml 的交互逻辑
  25. /// </summary>
  26. public partial class MarkModelWindow : Window
  27. {
  28. private bool isAdd = true;
  29. private MarkEntity markEntity = null;
  30. public MarkModelWindow(MarkEntity p, MarkModelTypeEntity markModelTypeEntity, ObservableCollection<MarkKeyEntity> keySource)
  31. {
  32. try
  33. {
  34. InitializeComponent();
  35. this.Owner = AppData.Instance.MainWindow;
  36. markEntity = p;
  37. MarkTypeSource = new ObservableCollection<MarkModelTypeEntity> { markModelTypeEntity };
  38. this._markType_ComBox.SelectedIndex = 0;
  39. MarkKeySource = keySource;
  40. this._parent_ComBox.ItemsSource = new List<MarkEntity> { p.ParentMark };
  41. this.Closed += (a, b) => AppData.Instance.MainWindow.Activate();
  42. }
  43. catch (Exception ex)
  44. {
  45. ExLog(ex, "MarkModelWindow");
  46. }
  47. }
  48. public MarkModelWindow(MarkEntity p, MarkModelTypeEntity markModelTypeEntity, ObservableCollection<MarkKeyEntity> keySource, bool b)
  49. {
  50. try
  51. {
  52. InitializeComponent();
  53. this.Owner = AppData.Instance.MainWindow;
  54. this._parent_ComBox.ItemsSource = new List<MarkEntity> { p.ParentMark };
  55. isAdd = false;
  56. markEntity = p;
  57. MarkTypeSource = new ObservableCollection<MarkModelTypeEntity> { markModelTypeEntity };
  58. this._markType_ComBox.SelectedIndex = 0;
  59. MarkKeySource = keySource;
  60. //this._title_TextBlock.Text = "编辑";
  61. this._title_TextBlock.Text = KeyToStringConvert.GetLanguageStringByKey("0083");
  62. this._orderNum_TextBox.Text = markEntity.orderNum.ToString();
  63. this._markKey_ComBox.SelectedItem = MarkKeySource.FirstOrDefault(x => x.markKey == markEntity.markKey);
  64. this._weight_TextBox.Text = markEntity.weight.ToString("F2");
  65. //关键值计算
  66. if (UnitSource.ContainsKey(markEntity.unit))
  67. {
  68. this._unit_ComBox.SelectedItem = UnitSource.FirstOrDefault(x => x.Key == markEntity.unit);
  69. }
  70. if (markEntity.child == 0) this._noChildren_RadioButton.IsChecked = true;
  71. if (markEntity.defaultValue == 1) this._defeat_RadioButton.IsChecked = true;
  72. if (markEntity.keyNode == 1) this._scores_CheckBox.IsChecked = true;
  73. this._markKey_ComBox.IsEnabled = false;
  74. this.Closed += (a, b) => AppData.Instance.MainWindow.Activate();
  75. }
  76. catch (Exception ex)
  77. {
  78. ExLog(ex, "MarkModelWindow");
  79. }
  80. }
  81. private void Cancel_Click(object sender, RoutedEventArgs e)
  82. {
  83. this.DialogResult = false;
  84. return;
  85. }
  86. private void Ok_Click(object sender, RoutedEventArgs e)
  87. {
  88. try
  89. {
  90. if (int.TryParse(this._orderNum_TextBox.Text.Trim(), out int newNum) && newNum >= 0)
  91. {
  92. }
  93. else
  94. {
  95. //MessageBoxShow("显示序号只能输入大于0的数字");
  96. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0284"));
  97. return;
  98. }
  99. if (decimal.TryParse(this._weight_TextBox.Text.Trim(), out decimal newWeight) && newWeight >= 0)
  100. {
  101. }
  102. else
  103. {
  104. //MessageBoxShow("权重值只能输入0-100的数字");
  105. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0288"));
  106. return;
  107. }
  108. int newChild = 1;
  109. if (this._noChildren_RadioButton.IsChecked == true) newChild = 0;
  110. int newDef = 0;
  111. if (this._defeat_RadioButton.IsChecked == true) newDef = 1;
  112. var cKey = (MarkKeyEntity)this._markKey_ComBox.SelectedItem;
  113. if (cKey == null)
  114. {
  115. //MessageBoxShow("请选择阶段名称");
  116. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0116"));
  117. return;
  118. }
  119. var cUnit = (KeyValuePair<int, string>)this._unit_ComBox.SelectedItem;
  120. if (cUnit.Key == 0)
  121. {
  122. //MessageBoxShow("请选择权重值单位");
  123. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0226"));
  124. return;
  125. }
  126. if (newChild == 0 && cUnit.Value == "%")
  127. {
  128. //MessageBoxShow("不存在下级节点时,单位只能是分");
  129. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0297"));
  130. return;
  131. }
  132. if (newChild == 1 && cUnit.Value == "分")
  133. {
  134. //MessageBoxShow("存在下级节点时,单位只能是%");
  135. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0298"));
  136. return;
  137. }
  138. int newKeyNode = 0;
  139. if (this._scores_CheckBox.IsChecked == true) newKeyNode = 1;
  140. MarkModelResponse newEntity = new MarkModelResponse();
  141. newEntity.id = markEntity.id;
  142. newEntity.child = newChild;
  143. //newEntity.defaultValue = newDef;
  144. newEntity.keyId = cKey.id;
  145. newEntity.markKey = cKey.markKey;
  146. newEntity.name = cKey.name;
  147. newEntity.keyNode = newKeyNode;
  148. newEntity.orderNum = newNum;
  149. newEntity.weight = newWeight;
  150. newEntity.unit = cUnit.Key;
  151. newEntity.state = markEntity.state;
  152. newEntity.parentId = markEntity.parentId;
  153. newEntity.model = markEntity.model;
  154. newEntity.level = markEntity.level;
  155. var pro = AppData.Instance.GetMarkSettingProvider();
  156. string error = null;
  157. if (isAdd) error = pro.AddMarkEntityApi(newEntity);
  158. else error = pro.UpdateMarkEntityApi(JsonConvert.SerializeObject(newEntity));
  159. if (!string.IsNullOrEmpty(error))
  160. {
  161. //MessageBoxShow($"操作失败,{error}");
  162. MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0286")},{error}");
  163. return;
  164. }
  165. markEntity.keyNode = newEntity.keyNode;
  166. markEntity.id = newEntity.id;
  167. markEntity.child = newEntity.child;
  168. //markEntity.defaultValue = newEntity.defaultValue;
  169. markEntity.markKey = newEntity.markKey;
  170. markEntity.model = newEntity.model;
  171. markEntity.name = newEntity.name;
  172. markEntity.orderNum = newEntity.orderNum;
  173. markEntity.parentId = newEntity.parentId;
  174. markEntity.state = newEntity.state;
  175. markEntity.unit = newEntity.unit;
  176. markEntity.weight = newEntity.weight;
  177. markEntity.level = newEntity.level;
  178. this.DialogResult = true;
  179. return;
  180. }
  181. catch (Exception ex)
  182. {
  183. ExLog(ex, "Ok_Click");
  184. MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0291")},{ex.Message}");
  185. }
  186. }
  187. public ObservableCollection<MarkModelTypeEntity> MarkTypeSource
  188. {
  189. get { return (ObservableCollection<MarkModelTypeEntity>)GetValue(MarkTypeSourceProperty); }
  190. set { SetValue(MarkTypeSourceProperty, value); }
  191. }
  192. // Using a DependencyProperty as the backing store for MarkTypeSource. This enables animation, styling, binding, etc...
  193. public static readonly DependencyProperty MarkTypeSourceProperty =
  194. DependencyProperty.Register("MarkTypeSource", typeof(ObservableCollection<MarkModelTypeEntity>), typeof(MarkModelWindow), new PropertyMetadata(null));
  195. public ObservableCollection<MarkKeyEntity> MarkKeySource
  196. {
  197. get { return (ObservableCollection<MarkKeyEntity>)GetValue(MarkKeySourceProperty); }
  198. set { SetValue(MarkKeySourceProperty, value); }
  199. }
  200. // Using a DependencyProperty as the backing store for MarkKeySource. This enables animation, styling, binding, etc...
  201. public static readonly DependencyProperty MarkKeySourceProperty =
  202. DependencyProperty.Register("MarkKeySource", typeof(ObservableCollection<MarkKeyEntity>), typeof(MarkModelWindow), new PropertyMetadata(null));
  203. public Dictionary<int, string> UnitSource
  204. {
  205. get { return (Dictionary<int, string>)GetValue(UnitSourceProperty); }
  206. set { SetValue(UnitSourceProperty, value); }
  207. }
  208. // Using a DependencyProperty as the backing store for UnitSource. This enables animation, styling, binding, etc...
  209. public static readonly DependencyProperty UnitSourceProperty =
  210. DependencyProperty.Register("UnitSource", typeof(Dictionary<int, string>), typeof(MarkModelWindow), new PropertyMetadata(new Dictionary<int, string> { { 2, "%" }, { 1, "分" } }));
  211. private void MessageBoxShow(string mess)
  212. {
  213. this.message.Text = mess;
  214. }
  215. private void ExLog(Exception ex, string name)
  216. {
  217. AppData.Instance.LogService.ExceptionLog(ex, $"MarkQucikWindow.{name}", LogEnum.RunException);
  218. }
  219. private void ErrorLog(string message, LogEnum logType)
  220. {
  221. AppData.Instance.LogService.TLLog($"MarkQucikWindow.{message}", logType);
  222. }
  223. }
  224. }