using System; using CustomUI; using System.Windows; using System.Windows.Input; using System.Windows.Threading; using SHJX.Service.Model.Control; using System.Text.RegularExpressions; namespace SHJX.Service.CustomControl { /// /// InputDialog.xaml 的交互逻辑 /// public partial class InputDialog : Window { public InputDialog() { Owner = Application.Current.MainWindow; InitializeComponent(); } public InputDialog(bool isUpdate, SampleDetail detail) { Owner = Application.Current.MainWindow; InitializeComponent(); txt_point.Text = detail.NodeName.Substring(1); txt_point.IsEnabled = isUpdate; foreach (SegmentItem item in cb_Mode.Items) { if (item.Content.Equals(detail.SampleType)) { cb_Mode.SelectedItem = item; } } } public string TextPoint => string.Concat("A", txt_point.Text); public string TextType => (cb_Mode.SelectedItem as SegmentItem).Content.ToString(); public string TextConcentration=> (cb_concentration.SelectedItem as SegmentItem).Content.ToString(); private void btnDialogOk_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(txt_point.Text)) { DialogResult = false; return; } Regex reg = new Regex(@"[^0-9]"); try { if (reg.IsMatch(txt_point.Text.ToString())) { txt_point.Text = string.Empty; return; } var num = Convert.ToInt32(txt_point.Text); if (num < 1 || num > 48) { txt_point.Text = string.Empty; return; } } finally { TextPointGetFocus(); } DialogResult = true; } private void Window_Loaded(object sender, RoutedEventArgs e) { TextPointGetFocus(); } private void TextPointGetFocus() { Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)(() => { Keyboard.Focus(txt_point); })); } private void StackPanel_MouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { DragMove(); } } } }