BusWindow.xaml.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using ivf_tl_Entity.Entity.AppSetting;
  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.Data.SqlTypes;
  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. /// BusWindow.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class BusWindow : Window
  25. {
  26. private Business CurrentBusiness { get; set; } = null;
  27. private bool isAdd = true;
  28. public BusWindow()
  29. {
  30. InitializeComponent();
  31. this.Owner = AppData.Instance.MainWindow;
  32. this.Closed += (a, b) =>
  33. {
  34. AppData.Instance.MainWindow.Activate();
  35. };
  36. }
  37. public BusWindow(Business business)
  38. {
  39. InitializeComponent();
  40. this.Owner = AppData.Instance.MainWindow;
  41. CurrentBusiness = business;
  42. isAdd = false;
  43. //this._title_TextBlock.Text = "编辑";
  44. this._title_TextBlock.Text = KeyToStringConvert.GetLanguageStringByKey("0083");
  45. this._name_TextBox.Text = business.name;
  46. this._key_TextBox.Text = business.functionKey;
  47. this._key_TextBox.IsEnabled = false;
  48. this.Closed += (a, b) =>
  49. {
  50. AppData.Instance.MainWindow.Activate();
  51. };
  52. }
  53. private void MessageBoxShow(string mess)
  54. {
  55. this.message.Text = mess;
  56. }
  57. private void ExLog(Exception ex, string name)
  58. {
  59. AppData.Instance.LogService.ExceptionLog(ex, $"BusWindow.{name}", LogEnum.RunException);
  60. }
  61. private void ErrorLog(string message, LogEnum logType)
  62. {
  63. AppData.Instance.LogService.TLLog($"BusWindow.{message}", logType);
  64. }
  65. private void Cancel_MouseUp(object sender, MouseButtonEventArgs e)
  66. {
  67. this.DialogResult = false;
  68. return;
  69. }
  70. private void Cancel_Click(object sender, RoutedEventArgs e)
  71. {
  72. this.DialogResult = false;
  73. return;
  74. }
  75. private void Ok_Click(object sender, RoutedEventArgs e)
  76. {
  77. try
  78. {
  79. string nameString = this._name_TextBox.Text.Trim();
  80. if (string.IsNullOrEmpty(nameString))
  81. {
  82. //MessageBoxShow($"业务名称不能为空");
  83. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0147"));
  84. return;
  85. }
  86. string keyString = this._key_TextBox.Text.Trim();
  87. if (string.IsNullOrEmpty(keyString))
  88. {
  89. //MessageBoxShow($"业务KEY不能为空");
  90. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0148"));
  91. return;
  92. }
  93. var pro = AppData.Instance.GetSettingProvider();
  94. string error = null;
  95. if (isAdd)
  96. {
  97. string body = JsonConvert.SerializeObject(new
  98. {
  99. name = nameString,
  100. functionKey = keyString,
  101. });
  102. error = pro.AddBusApi(body);
  103. }
  104. else
  105. {
  106. string body = JsonConvert.SerializeObject(new
  107. {
  108. name = nameString,
  109. id = CurrentBusiness.id
  110. });
  111. error = pro.EditBusApi(body);
  112. }
  113. if (!string.IsNullOrEmpty(error))
  114. {
  115. //MessageBoxShow($"操作失败,{error}");
  116. MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0286")},{error}");
  117. return;
  118. }
  119. if(!isAdd) CurrentBusiness.name = nameString;
  120. this.DialogResult = true;
  121. return;
  122. }
  123. catch (Exception ex)
  124. {
  125. ExLog(ex, "");
  126. MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0291")},{ex.Message}");
  127. }
  128. }
  129. }
  130. }