AlarmUserWindow.xaml.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using ivf_tl_Entity.Entity.Alarm;
  2. using ivf_tl_Entity.Entity.Mark;
  3. using ivf_tl_Entity.Enums;
  4. using ivf_tl_Manage.Converts;
  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. /// AlarmUserWindow.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class AlarmUserWindow : Window
  25. {
  26. private bool isAdd = true;
  27. private AlarmUserEntity alarmUser = null;
  28. public AlarmUserWindow()
  29. {
  30. try
  31. {
  32. InitializeComponent();
  33. this.Owner = AppData.Instance.MainWindow;
  34. this.Closed += (a, b) => AppData.Instance.MainWindow.Activate();
  35. }
  36. catch (Exception ex)
  37. {
  38. ExLog(ex, "AlarmUserWindow");
  39. }
  40. }
  41. public AlarmUserWindow(AlarmUserEntity editAlarm)
  42. {
  43. try
  44. {
  45. InitializeComponent();
  46. this.Owner = AppData.Instance.MainWindow;
  47. alarmUser = editAlarm;
  48. isAdd = false;
  49. //this._title_TextBlock.Text = "编辑";
  50. this._title_TextBlock.Text = KeyToStringConvert.GetLanguageStringByKey("0083");
  51. this._name_TextBox.Text = alarmUser.name;
  52. this._phone_TextBox.Text = alarmUser.phone;
  53. if (alarmUser.sms == 1) this._sms_CheckBox.IsChecked = true;
  54. if (alarmUser.tel == 1) this._call_CheckBox.IsChecked = true;
  55. this.Closed += (a, b) => AppData.Instance.MainWindow.Activate();
  56. }
  57. catch (Exception ex)
  58. {
  59. ExLog(ex, "AlarmUserWindow");
  60. }
  61. }
  62. private void Cancel_Click(object sender, RoutedEventArgs e)
  63. {
  64. this.DialogResult = false;
  65. return;
  66. }
  67. private void Ok_Click(object sender, RoutedEventArgs e)
  68. {
  69. try
  70. {
  71. string nameString = this._name_TextBox.Text.Trim();
  72. if (string.IsNullOrEmpty(nameString))
  73. {
  74. //MessageBoxShow("通知对象不能为空");
  75. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0182"));
  76. return;
  77. }
  78. string phoneString = this._phone_TextBox.Text.Trim();
  79. if (string.IsNullOrEmpty(phoneString))
  80. {
  81. //MessageBoxShow("联系方式不能为空");
  82. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0183"));
  83. return;
  84. }
  85. int smsState = 0;
  86. if (this._sms_CheckBox.IsChecked == true) smsState = 1;
  87. int callState = 0;
  88. if (this._call_CheckBox.IsChecked == true) callState = 1;
  89. if (smsState == 0 && callState == 0)
  90. {
  91. //MessageBoxShow("至少选择一种通知方式");
  92. MessageBoxShow(KeyToStringConvert.GetLanguageStringByKey("0312"));
  93. return;
  94. }
  95. var pro = AppData.Instance.GetAlarmProvider();
  96. string error = null;
  97. if (isAdd) error = pro.AddAlarmUserApi(nameString, phoneString, smsState, callState);
  98. else
  99. {
  100. error = pro.UpdateAlarmUserApi(alarmUser.id, nameString, phoneString, smsState, callState);
  101. }
  102. if (!string.IsNullOrEmpty(error))
  103. {
  104. //MessageBoxShow($"操作失败,{error}");
  105. MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0286")},{error}");
  106. return;
  107. }
  108. if (!isAdd)
  109. {
  110. alarmUser.name = nameString;
  111. alarmUser.phone = phoneString;
  112. alarmUser.sms = smsState;
  113. alarmUser.tel = callState;
  114. }
  115. this.DialogResult = true;
  116. return;
  117. }
  118. catch (Exception ex)
  119. {
  120. ExLog(ex, "Ok_Click");
  121. //MessageBoxShow($"操作失败:{ex.Message}");
  122. MessageBoxShow($"{KeyToStringConvert.GetLanguageStringByKey("0291")}:{ex.Message}");
  123. }
  124. }
  125. private void MessageBoxShow(string mess)
  126. {
  127. this.message.Text = mess;
  128. }
  129. private void ExLog(Exception ex, string name)
  130. {
  131. AppData.Instance.LogService.ExceptionLog(ex, $"AlarmUserWindow.{name}", LogEnum.RunException);
  132. }
  133. private void ErrorLog(string message, LogEnum logType)
  134. {
  135. AppData.Instance.LogService.TLLog($"AlarmUserWindow.{message}", logType);
  136. }
  137. }
  138. }