MarkWeightOneWindow.xaml.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Shapes;
  19. namespace ivf_tl_Manage.Win
  20. {
  21. /// <summary>
  22. /// MarkWeightOneWindow.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class MarkWeightOneWindow : Window
  25. {
  26. private bool isAdd = true;
  27. private MarkWeight MarkWeight { get; set; } = null;
  28. public MarkWeightOneWindow(MarkWeight _MarkWeight)
  29. {
  30. InitializeComponent();
  31. this.Owner = AppData.Instance.MainWindow;
  32. MarkWeight = _MarkWeight;
  33. this.Closed += (a, b) => AppData.Instance.MainWindow.Activate();
  34. }
  35. public MarkWeightOneWindow(MarkWeight _MarkWeight, bool b)
  36. {
  37. InitializeComponent();
  38. this._title_TextBlock.Text = KeyToStringConvert.GetLanguageStringByKey("0083");
  39. this.Owner = AppData.Instance.MainWindow;
  40. isAdd = false;
  41. MarkWeight = _MarkWeight;
  42. this._name_TextBox.Text = MarkWeight.name;
  43. this._orderNum_TextBox.Text = MarkWeight.orderNum.ToString();
  44. this.Closed += (a, b) => AppData.Instance.MainWindow.Activate();
  45. }
  46. private void Ok_Click(object sender, RoutedEventArgs e)
  47. {
  48. try
  49. {
  50. string markNameString = this._name_TextBox.Text.Trim();
  51. string orderNumString = this._orderNum_TextBox.Text.Trim();
  52. if (string.IsNullOrEmpty(markNameString))
  53. {
  54. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0228"));
  55. return;
  56. }
  57. if (string.IsNullOrEmpty(orderNumString))
  58. {
  59. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0563"));
  60. return;
  61. }
  62. if (!int.TryParse(orderNumString, out int orderNumInt))
  63. {
  64. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0563"));
  65. return;
  66. }
  67. MarkWeightNoParent newWeight = new MarkWeightNoParent();
  68. newWeight.id = MarkWeight.id;
  69. newWeight.name = markNameString;
  70. newWeight.orderNum = orderNumInt;
  71. newWeight.weight = MarkWeight.weight;
  72. newWeight.markKey = MarkWeight.markKey;
  73. MarkSettingProvider markSettingProvider = AppData.Instance.GetMarkSettingProvider();
  74. string error = null;
  75. if (isAdd)
  76. {
  77. newWeight.markKey = newWeight.name;
  78. error = markSettingProvider.AddMarkWeightApi(newWeight);
  79. }
  80. else error = markSettingProvider.UpdateMarkWeightApi(JsonConvert.SerializeObject(newWeight));
  81. if (!string.IsNullOrEmpty(error))
  82. {
  83. MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0286")},{error}");
  84. return;
  85. }
  86. MarkWeight.id = newWeight.id;
  87. MarkWeight.markKey = newWeight.markKey;
  88. MarkWeight.name = newWeight.name;
  89. MarkWeight.orderNum = newWeight.orderNum;
  90. MarkWeight.weight = newWeight.weight;
  91. this.DialogResult = true;
  92. return;
  93. }
  94. catch (Exception ex)
  95. {
  96. ExLog(ex, "Ok_Click");
  97. }
  98. }
  99. private void MessageBoxShow(string mess)
  100. {
  101. this.message.Text = mess;
  102. }
  103. private void ExLog(Exception ex, string name)
  104. {
  105. AppData.Instance.LogService.ExceptionLog(ex, $"MarkWeightOneWindow.{name}", LogEnum.RunException);
  106. }
  107. private void ErrorLog(string message, LogEnum logType)
  108. {
  109. AppData.Instance.LogService.TLLog($"MarkWeightOneWindow.{message}", logType);
  110. }
  111. private void Cancel_Click(object sender, RoutedEventArgs e)
  112. {
  113. this.DialogResult = false;
  114. return;
  115. }
  116. private void Cancel_MouseUp(object sender, MouseButtonEventArgs e)
  117. {
  118. this.DialogResult = false;
  119. return;
  120. }
  121. }
  122. }