| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- 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
- {
- /// <summary>
- /// InputDialog.xaml 的交互逻辑
- /// </summary>
- 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");
- }
- }
- }
|