|
|
@@ -0,0 +1,83 @@
|
|
|
+using InABox.Wpf;
|
|
|
+using System;
|
|
|
+using System.Windows;
|
|
|
+
|
|
|
+namespace InABox.WPF
|
|
|
+{
|
|
|
+ /// <summary>
|
|
|
+ /// Interaction logic for NumberEdit.xaml
|
|
|
+ /// </summary>
|
|
|
+ public partial class DecimalEdit : ThemableWindow
|
|
|
+ {
|
|
|
+ public DecimalEdit(string title, decimal min, decimal max, int decimals, decimal value)
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+ Title = title;
|
|
|
+ Value = value;
|
|
|
+ Editor.NumberDecimalDigits = decimals;
|
|
|
+ Editor.MinValue = Convert.ToDouble(min);
|
|
|
+ Editor.MaxValue = Convert.ToDouble(max);
|
|
|
+ }
|
|
|
+
|
|
|
+ public int DecimalPlaces
|
|
|
+ {
|
|
|
+ get => Editor.NumberDecimalDigits;
|
|
|
+ set => Editor.NumberDecimalDigits = value;
|
|
|
+ }
|
|
|
+
|
|
|
+ public decimal Value
|
|
|
+ {
|
|
|
+ get => Convert.ToDecimal(Editor.Value.HasValue ? Editor.Value.Value : 0);
|
|
|
+ set => Editor.Value = Convert.ToDouble(value);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Confirm()
|
|
|
+ {
|
|
|
+ if (Editor.Value >= Editor.MinValue && Editor.Value <= Editor.MaxValue)
|
|
|
+ {
|
|
|
+ DialogResult = true;
|
|
|
+ Close();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MessageBox.Show($"Value must be in range [{Editor.MinValue}, {Editor.MaxValue}]");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void OK_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ Confirm();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Cancel_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ DialogResult = false;
|
|
|
+ Close();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static bool Execute(string title, decimal min, decimal max, int decimals, ref decimal value)
|
|
|
+ {
|
|
|
+ var edit = new DecimalEdit(title, min, max, decimals, value);
|
|
|
+ if (edit.ShowDialog() == true)
|
|
|
+ {
|
|
|
+ value = edit.Value;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ThemableWindow_Loaded(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ Editor.Focus();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Editor_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
|
|
|
+ {
|
|
|
+ if(e.Key == System.Windows.Input.Key.Enter)
|
|
|
+ {
|
|
|
+ Confirm();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|