MarkModelOneWindow.xaml.cs 11 KB

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