InputDialog.xaml.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using CustomUI;
  3. using System.Windows;
  4. using System.Windows.Input;
  5. using System.Windows.Threading;
  6. using SHJX.Service.Model.CRUDModules;
  7. using System.Text.RegularExpressions;
  8. using SHJX.Service.Model.Enums;
  9. namespace SHJX.Service.Library.Views.CustomDialog
  10. {
  11. /// <summary>
  12. /// InputDialog.xaml 的交互逻辑
  13. /// </summary>
  14. public partial class InputDialog : Window
  15. {
  16. public string TextPoint => string.Concat("A", txt_point.Text);
  17. public string TextType => (cb_mode.SelectedItem as SegmentItem).Content.ToString();
  18. public bool IsCalibration => (bool)cb_calibration.IsChecked;
  19. public double SampleVolume => Convert.ToDouble(txt_volume.Text);
  20. public double SampleMultiple => Convert.ToDouble(txt_multiple.Text);
  21. public AcidBase Acid => (bool)rb_acid.IsChecked ? AcidBase.Acid : AcidBase.Alkali;
  22. public InputDialog()
  23. {
  24. Owner = Application.Current.MainWindow;
  25. InitializeComponent();
  26. txt_volume.Text = "100";
  27. txt_multiple.Text = "0";
  28. cb_calibration.IsChecked = false;
  29. cb_calibration.IsEnabled = false;
  30. cb_mode.SelectedItem = cb_mode.Items[0];
  31. rb_acid.IsChecked = true;
  32. }
  33. public InputDialog(bool isUpdate, SampleDetail detail)
  34. {
  35. Owner = Application.Current.MainWindow;
  36. InitializeComponent();
  37. cb_calibration.IsEnabled = detail.SampleType.Equals("空白");
  38. cb_calibration.IsChecked = detail.IsCalibration;
  39. rb_acid.IsChecked = detail.AcidBaseProp.Equals(AcidBase.Acid);
  40. rb_alkali.IsChecked = detail.AcidBaseProp.Equals(AcidBase.Alkali);
  41. txt_volume.Text = detail.SampleVolume.ToString();
  42. txt_multiple.Text = detail.SampleMultiple.ToString();
  43. txt_point.Text = detail.NodeName[1..];
  44. txt_point.IsEnabled = isUpdate;
  45. foreach (SegmentItem item in cb_mode.Items)
  46. {
  47. if (item.Content.Equals(detail.SampleType))
  48. {
  49. cb_mode.SelectedItem = item;
  50. }
  51. }
  52. }
  53. private void btnDialogOk_Click(object sender, RoutedEventArgs e)
  54. {
  55. if (string.IsNullOrWhiteSpace(txt_point.Text))
  56. {
  57. DialogResult = false;
  58. return;
  59. }
  60. Regex reg = new(@"[^0-9]");
  61. try
  62. {
  63. if (reg.IsMatch(txt_point.Text.ToString()))
  64. {
  65. txt_point.Text = string.Empty;
  66. return;
  67. }
  68. int num = Convert.ToInt32(txt_point.Text);
  69. if (num is < 1 or > 55)
  70. {
  71. txt_point.Text = string.Empty;
  72. return;
  73. }
  74. }
  75. finally
  76. {
  77. TextPointGetFocus();
  78. }
  79. DialogResult = true;
  80. }
  81. private void Window_Loaded(object sender, RoutedEventArgs e)
  82. {
  83. TextPointGetFocus();
  84. }
  85. private void TextPointGetFocus()
  86. {
  87. Dispatcher.BeginInvoke(DispatcherPriority.Background, () =>
  88. {
  89. Keyboard.Focus(txt_point);
  90. });
  91. }
  92. private void StackPanel_MouseMove(object sender, MouseEventArgs e)
  93. {
  94. if (e.LeftButton == MouseButtonState.Pressed)
  95. {
  96. DragMove();
  97. }
  98. }
  99. private void cb_mode_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
  100. {
  101. if ((cb_mode.SelectedItem as SegmentItem).Content.ToString().Equals("样品"))
  102. {
  103. cb_calibration.IsChecked = false;
  104. }
  105. cb_calibration.IsEnabled = (cb_mode.SelectedItem as SegmentItem).Content.ToString().Equals("样品") ? false : true;
  106. }
  107. private void txt_volume_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
  108. {
  109. if (string.IsNullOrWhiteSpace(txt_volume.Text))
  110. {
  111. return;
  112. }
  113. double volume = Convert.ToDouble(txt_volume.Text);
  114. txt_multiple.Text = ((100 - volume) / 100).ToString("F3");
  115. }
  116. }
  117. }