MarkWeightWindow.xaml.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using ivf_tl_Entity.Entity.Mark;
  2. using ivf_tl_Entity.Enums;
  3. using ivf_tl_Manage.Converts;
  4. using ivf_tl_Service.HttpProvider;
  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. /// MarkWeightWindow.xaml 的交互逻辑
  24. /// </summary>
  25. public partial class MarkWeightWindow : Window
  26. {
  27. private bool isAdd = true;
  28. private MarkWeight MarkWeight { get; set; } = null;
  29. public MarkWeightWindow(MarkWeight _MarkWeight, ObservableCollection<MarkEntity> MarkEntityList)
  30. {
  31. try
  32. {
  33. InitializeComponent();
  34. this.Owner = AppData.Instance.MainWindow;
  35. this._markKey_ComBox.ItemsSource = MarkEntityList;
  36. MarkWeight = _MarkWeight;
  37. if (_MarkWeight.ParentMarkWeight == null)
  38. {
  39. this._ParentId_Grid.Visibility = Visibility.Collapsed;
  40. }
  41. else
  42. {
  43. this._parentID_TextBox.Text = _MarkWeight.ParentMarkWeight.name;
  44. }
  45. this.Closed += (a, b) => AppData.Instance.MainWindow.Activate();
  46. }
  47. catch (Exception ex)
  48. {
  49. ExLog(ex, "MarkWeightWindow");
  50. }
  51. }
  52. public MarkWeightWindow(MarkWeight _MarkWeight, ObservableCollection<MarkEntity> MarkEntityList, bool b)
  53. {
  54. try
  55. {
  56. isAdd = false;
  57. InitializeComponent();
  58. this._markKey_ComBox.ItemsSource = MarkEntityList;
  59. this.Owner = AppData.Instance.MainWindow;
  60. isAdd = false;
  61. MarkWeight = _MarkWeight;
  62. if (_MarkWeight.ParentMarkWeight == null)
  63. {
  64. this._ParentId_Grid.Visibility = Visibility.Collapsed;
  65. }
  66. else
  67. {
  68. this._parentID_TextBox.Text = _MarkWeight.ParentMarkWeight.name;
  69. }
  70. this._title_TextBlock.Text = KeyToStringConvert.GetLanguageStringByKey("0083");
  71. //this._name_TextBox.Text = MarkWeight.name;
  72. this._markKey_ComBox.SelectedItem = MarkEntityList.FirstOrDefault(x => x.markKey == MarkWeight.markKey);
  73. //this._orderNum_TextBox.Text = MarkWeight.orderNum.ToString();
  74. this._weight_TextBox.Text = MarkWeight.weight.ToString();
  75. this.Closed += (a, b) => AppData.Instance.MainWindow.Activate();
  76. }
  77. catch (Exception ex)
  78. {
  79. ExLog(ex, "MarkWeightWindow");
  80. }
  81. }
  82. private void Cancel_MouseUp(object sender, MouseButtonEventArgs e)
  83. {
  84. this.DialogResult = false;
  85. return;
  86. }
  87. private void Cancel_Click(object sender, RoutedEventArgs e)
  88. {
  89. this.DialogResult = false;
  90. return;
  91. }
  92. private void Ok_Click(object sender, RoutedEventArgs e)
  93. {
  94. try
  95. {
  96. //string markKeyString = this._markKey_TextBox.Text.Trim();
  97. // string markNameString = this._name_TextBox.Text.Trim();
  98. //string orderNumString = this._orderNum_TextBox.Text.Trim();
  99. string weightString = this._weight_TextBox.Text.Trim();
  100. //if (string.IsNullOrEmpty(markNameString))
  101. //{
  102. // MessageBoxShow("名称不能为空");
  103. // return;
  104. //}
  105. //if (string.IsNullOrEmpty(markKeyString))
  106. //{
  107. // MessageBoxShow("MarkKey不能为空");
  108. // return;
  109. //}
  110. if (!(this._markKey_ComBox.SelectedItem is MarkEntity markEntity))
  111. {
  112. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0116"));
  113. return;
  114. }
  115. //if (string.IsNullOrEmpty(orderNumString))
  116. //{
  117. // MessageBoxShow("优先级不能为空");
  118. // return;
  119. //}
  120. //if (!int.TryParse(orderNumString, out int orderNumInt))
  121. //{
  122. // MessageBoxShow("优先级只能输入数字");
  123. // return;
  124. //}
  125. if (string.IsNullOrEmpty(weightString))
  126. {
  127. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0118"));
  128. return;
  129. }
  130. if (!decimal.TryParse(weightString, out decimal weightDouble))
  131. {
  132. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0288"));
  133. return;
  134. }
  135. MarkWeight newWeight = new MarkWeight();
  136. newWeight.id = MarkWeight.id;
  137. newWeight.markKey = markEntity.markKey;
  138. newWeight.name = markEntity.name;
  139. newWeight.orderNum = 1;
  140. newWeight.parentId = MarkWeight.parentId;
  141. newWeight.weight = weightDouble;
  142. MarkSettingProvider markSettingProvider = AppData.Instance.GetMarkSettingProvider();
  143. string error = null;
  144. if (isAdd) error = markSettingProvider.AddMarkWeightApi(newWeight);
  145. else error = markSettingProvider.UpdateMarkWeightApi(JsonConvert.SerializeObject(newWeight));
  146. if (!string.IsNullOrEmpty(error))
  147. {
  148. MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0286")},{error}");
  149. return;
  150. }
  151. MarkWeight.id = newWeight.id;
  152. MarkWeight.markKey = newWeight.markKey;
  153. MarkWeight.name = newWeight.name;
  154. MarkWeight.orderNum = newWeight.orderNum;
  155. MarkWeight.parentId = newWeight.parentId;
  156. MarkWeight.weight = newWeight.weight;
  157. this.DialogResult = true;
  158. return;
  159. }
  160. catch (Exception ex)
  161. {
  162. ExLog(ex, "Ok_Click");
  163. }
  164. }
  165. private void MessageBoxShow(string mess)
  166. {
  167. this.message.Text = mess;
  168. }
  169. private void ExLog(Exception ex, string name)
  170. {
  171. AppData.Instance.LogService.ExceptionLog(ex, $"MarkWeightWindow.{name}", LogEnum.RunException);
  172. }
  173. private void ErrorLog(string message, LogEnum logType)
  174. {
  175. AppData.Instance.LogService.TLLog($"MarkWeightWindow.{message}", logType);
  176. }
  177. }
  178. }