InputDialog.xaml.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.Control;
  7. using System.Text.RegularExpressions;
  8. namespace SHJX.Service.CustomControl
  9. {
  10. /// <summary>
  11. /// InputDialog.xaml 的交互逻辑
  12. /// </summary>
  13. public partial class InputDialog : Window
  14. {
  15. public InputDialog()
  16. {
  17. Owner = Application.Current.MainWindow;
  18. InitializeComponent();
  19. }
  20. public InputDialog(bool isUpdate, SampleDetail detail)
  21. {
  22. Owner = Application.Current.MainWindow;
  23. InitializeComponent();
  24. txt_point.Text = detail.NodeName.Substring(1);
  25. txt_point.IsEnabled = isUpdate;
  26. foreach (SegmentItem item in cb_Mode.Items)
  27. {
  28. if (item.Content.Equals(detail.SampleType))
  29. {
  30. cb_Mode.SelectedItem = item;
  31. }
  32. }
  33. }
  34. public string TextPoint => string.Concat("A", txt_point.Text);
  35. public string TextType => (cb_Mode.SelectedItem as SegmentItem).Content.ToString();
  36. public string TextConcentration=> (cb_concentration.SelectedItem as SegmentItem).Content.ToString();
  37. private void btnDialogOk_Click(object sender, RoutedEventArgs e)
  38. {
  39. if (string.IsNullOrWhiteSpace(txt_point.Text))
  40. {
  41. DialogResult = false;
  42. return;
  43. }
  44. Regex reg = new Regex(@"[^0-9]");
  45. try
  46. {
  47. if (reg.IsMatch(txt_point.Text.ToString()))
  48. {
  49. txt_point.Text = string.Empty;
  50. return;
  51. }
  52. var num = Convert.ToInt32(txt_point.Text);
  53. if (num < 1 || num > 48)
  54. {
  55. txt_point.Text = string.Empty;
  56. return;
  57. }
  58. }
  59. finally
  60. {
  61. TextPointGetFocus();
  62. }
  63. DialogResult = true;
  64. }
  65. private void Window_Loaded(object sender, RoutedEventArgs e)
  66. {
  67. TextPointGetFocus();
  68. }
  69. private void TextPointGetFocus()
  70. {
  71. Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)(() =>
  72. {
  73. Keyboard.Focus(txt_point);
  74. }));
  75. }
  76. private void StackPanel_MouseMove(object sender, MouseEventArgs e)
  77. {
  78. if (e.LeftButton == MouseButtonState.Pressed)
  79. {
  80. DragMove();
  81. }
  82. }
  83. }
  84. }