using System; using CustomUI; using System.Windows; using System.Windows.Input; using System.Windows.Threading; using SHJX.Service.Model.CRUDModules; using System.Text.RegularExpressions; using SHJX.Service.Model.Enums; namespace SHJX.Service.Library.Views.CustomDialog { /// /// InputDialog.xaml 的交互逻辑 /// public partial class InputDialog : Window { public string TextPoint => string.Concat("A", txt_point.Text); public string TextType => (cb_mode.SelectedItem as SegmentItem).Content.ToString(); public bool IsCalibration => (bool)cb_calibration.IsChecked; public double SampleVolume => Convert.ToDouble(txt_volume.Text); public double SampleMultiple => Convert.ToDouble(txt_multiple.Text); public AcidBase Acid => (bool)rb_acid.IsChecked ? AcidBase.Acid : AcidBase.Alkali; public InputDialog() { Owner = Application.Current.MainWindow; InitializeComponent(); txt_volume.Text = "100"; txt_multiple.Text = "0"; cb_calibration.IsChecked = false; cb_calibration.IsEnabled = false; cb_mode.SelectedItem = cb_mode.Items[0]; rb_acid.IsChecked = true; } public InputDialog(bool isUpdate, SampleDetail detail) { Owner = Application.Current.MainWindow; InitializeComponent(); cb_calibration.IsEnabled = detail.SampleType.Equals("空白"); cb_calibration.IsChecked = detail.IsCalibration; rb_acid.IsChecked = detail.AcidBaseProp.Equals(AcidBase.Acid); rb_alkali.IsChecked = detail.AcidBaseProp.Equals(AcidBase.Alkali); txt_volume.Text = detail.SampleVolume.ToString(); txt_multiple.Text = detail.SampleMultiple.ToString(); txt_point.Text = detail.NodeName[1..]; txt_point.IsEnabled = isUpdate; foreach (SegmentItem item in cb_mode.Items) { if (item.Content.Equals(detail.SampleType)) { cb_mode.SelectedItem = item; } } } private void btnDialogOk_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(txt_point.Text)) { DialogResult = false; return; } Regex reg = new(@"[^0-9]"); try { if (reg.IsMatch(txt_point.Text.ToString())) { txt_point.Text = string.Empty; return; } int num = Convert.ToInt32(txt_point.Text); if (num is < 1 or > 55) { 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, () => { Keyboard.Focus(txt_point); }); } private void StackPanel_MouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { DragMove(); } } private void cb_mode_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { if ((cb_mode.SelectedItem as SegmentItem).Content.ToString().Equals("样品")) { cb_calibration.IsChecked = false; } cb_calibration.IsEnabled = (cb_mode.SelectedItem as SegmentItem).Content.ToString().Equals("样品") ? false : true; } private void txt_volume_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) { if (string.IsNullOrWhiteSpace(txt_volume.Text)) { return; } double volume = Convert.ToDouble(txt_volume.Text); txt_multiple.Text = ((100 - volume) / 100).ToString("F3"); } } }