using HMI.Core.Util;
|
using HMI.UI.DpUtil;
|
using HMI.UI.Util;
|
using Panuon.WPF.UI;
|
using Plugin.ServoManage.Entity;
|
using System;
|
using System.Collections.ObjectModel;
|
using System.ComponentModel;
|
using System.Linq;
|
using System.Reflection;
|
using System.Windows.Controls;
|
|
namespace Plugin.ServoManage
|
{
|
/// <summary>
|
/// ModalWindow.xaml 的交互逻辑
|
/// </summary>
|
public partial class NumberPanel : WindowX
|
{
|
public NumberPanel()
|
{
|
this.DataContext = this;
|
InitializeComponent();
|
}
|
|
public double? Data { get; private set; }
|
|
private bool _isProcessing;
|
|
protected override void OnClosing(CancelEventArgs e)
|
{
|
//Press Continue Button
|
if (DialogResult == true)
|
{
|
if (_isProcessing)
|
{
|
e.Cancel = true;
|
return;
|
}
|
try
|
{
|
|
}
|
catch (Exception ex)
|
{
|
|
return;
|
}
|
finally
|
{
|
_isProcessing = false;
|
}
|
}
|
base.OnClosing(e);
|
}
|
|
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
|
{
|
Button btn = sender as Button;
|
switch (btn.Tag.ToString())
|
{
|
case "LeftArrow":
|
break;
|
case "RightArrow":
|
break;
|
case "AC":
|
NiNumber.Text = null;
|
break;
|
case "Backspace":
|
HandleBackspace();
|
break;
|
case "Enter":
|
DialogResult = true;
|
Data = double.Parse(NiNumber.Text);
|
this.Close();
|
break;
|
case "ESC":
|
DialogResult = false;
|
this.Close();
|
break;
|
case "-":
|
var str = NiNumber.Text;
|
if (string.IsNullOrEmpty(str))
|
{
|
NiNumber.Text = "-";
|
}
|
else if (str.StartsWith("-"))
|
{
|
NiNumber.Text = str.Replace("-", "");
|
}
|
else
|
{
|
NiNumber.Text = "-" + str;
|
}
|
break;
|
case ".":
|
HandleDot();
|
break;
|
default:
|
HandleNumberInput(btn.Tag.ToString());
|
break;
|
}
|
}
|
|
private void HandleBackspace()
|
{
|
var str = NiNumber.Text?.ToString();
|
if (string.IsNullOrEmpty(str))
|
{
|
return;
|
}
|
else
|
{
|
NiNumber.Text = str.Substring(0, str.Length - 1);
|
}
|
}
|
|
private void HandleDot()
|
{
|
var str = NiNumber.Text?.ToString();
|
if (string.IsNullOrEmpty(str) || str.IndexOf(".") > 0)
|
{
|
return;
|
}
|
else
|
{
|
NiNumber.Text = str + ".";
|
}
|
}
|
|
public bool? Open(string dataStr)
|
{
|
try
|
{
|
Data = double.Parse(dataStr);
|
NiNumber.Text = dataStr;
|
}
|
catch (Exception ex)
|
{
|
Data = null;
|
NiNumber.Text = null;
|
}
|
return this.ShowDialog();
|
}
|
|
private void HandleNumberInput(string numStr)
|
{
|
var str = NiNumber.Text?.ToString();
|
if (string.IsNullOrEmpty(str))
|
{
|
NiNumber.Text = numStr;
|
}
|
else
|
{
|
NiNumber.Text = str + numStr;
|
}
|
}
|
|
}
|
}
|