using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Text.RegularExpressions;
|
using System.Threading.Tasks;
|
using System.Windows;
|
using System.Windows.Controls;
|
using System.Windows.Data;
|
using System.Windows.Documents;
|
using System.Windows.Forms;
|
using System.Windows.Input;
|
using System.Windows.Media;
|
using System.Windows.Media.Imaging;
|
using System.Windows.Navigation;
|
using System.Windows.Shapes;
|
using XCommon.Log;
|
using XHandler.Class.DataEx;
|
using XImagingXhandler.XDAL;
|
using System.CodeDom.Compiler;
|
using HandyControl.Data;
|
using XCommon.Tip;
|
|
namespace XHandler.View.MethodProperty
|
{
|
/// <summary>
|
/// SetVariableProperty.xaml 的交互逻辑
|
/// </summary>
|
public partial class SetVariableProperty : System.Windows.Controls.UserControl
|
{
|
public MethodSetVariable methodSetVariable { get; set; }
|
public MethodSetVariable currentMethodSetVariable = null;
|
CodeDomProvider provider = CodeDomProvider.CreateProvider("C#");
|
public MethodEx method = null;
|
|
#region 全局属性变量
|
string isrun = "";
|
string status = "";
|
string name = "";
|
string label = "";
|
bool enablePopWin = false;
|
string variableName = "";
|
string variableValue = "";
|
int mark = 0;
|
#endregion
|
|
public SetVariableProperty()
|
{
|
InitializeComponent();
|
}
|
|
public SetVariableProperty(MethodEx method)
|
{
|
InitializeComponent();
|
tbxCommandLabel.Text = method.method_name;
|
methodSetVariable = new MethodSetVariable();
|
methodSetVariable.name = method.method_name;
|
methodSetVariable.label = method.method_name;
|
methodSetVariable.status = (method.isEnabled == true ? "enable" : "disable");
|
methodSetVariable.strIndex = method.strIndex;
|
this.method = method;
|
if (method.tag != null)
|
{
|
methodSetVariable = (MethodSetVariable)method.tag;
|
|
currentMethodSetVariable = methodSetVariable;
|
|
isrun = methodSetVariable.isrun;
|
status = methodSetVariable.status;
|
name = methodSetVariable.name;
|
label = methodSetVariable.label;
|
enablePopWin = methodSetVariable.enablepopwin;
|
variableName = methodSetVariable.variablename;
|
variableValue = methodSetVariable.variablevalue;
|
}
|
this.DataContext = methodSetVariable;
|
}
|
|
private void cbxEnablePopWin_Click(object sender, RoutedEventArgs e)
|
{
|
try
|
{
|
if (cbxEnablePopWin.IsChecked == true)
|
{
|
if (methodSetVariable != null)
|
{
|
methodSetVariable.enablepopwin = true;
|
}
|
}
|
else
|
{
|
if (methodSetVariable != null)
|
{
|
methodSetVariable.enablepopwin = false;
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
}
|
|
private void tbxVariableName_TextChanged(object sender, TextChangedEventArgs e)
|
{
|
try
|
{
|
if (provider.IsValidIdentifier(tbxVariableName.Text.ToString()))
|
{
|
tbxVariableName.BorderThickness = new Thickness(0, 0, 0, 0);
|
tbxVariableName.BorderBrush = Brushes.Transparent;
|
}
|
else
|
{
|
tbxVariableName.BorderThickness=new Thickness(1,1,1,1);
|
tbxVariableName.BorderBrush = Brushes.Red;
|
ShowTip.ShowNotice(string.Format("{0}{1}{2}", "提醒", Environment.NewLine, "变量名称不符合规范"), InfoType.Warning);
|
return;
|
}
|
|
if (methodSetVariable != null)
|
{
|
methodSetVariable.variablename = tbxVariableName.Text;
|
if (this.method != null)
|
{
|
this.method.method_Tipcontent = string.Format("{0}={1}", methodSetVariable.variablename.ToString(), methodSetVariable.variablevalue.ToString());
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
}
|
|
private void tbxVariableValue_TextChanged(object sender, TextChangedEventArgs e)
|
{
|
try
|
{
|
if (methodSetVariable != null)
|
{
|
methodSetVariable.variablevalue = tbxVariableValue.Text;
|
if (this.method != null)
|
{
|
this.method.method_Tipcontent = string.Format("{0}={1}", methodSetVariable.variablename.ToString(), methodSetVariable.variablevalue.ToString());
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
}
|
|
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
{
|
mark += 1;
|
try
|
{
|
if (mark > 1)
|
{
|
return;
|
}
|
if (!string.IsNullOrEmpty(variableName))
|
{
|
tbxCommandName.Text = name;
|
if(enablePopWin)
|
{
|
cbxEnablePopWin.IsChecked = true;
|
}
|
tbxVariableName.Text = variableName;
|
tbxVariableValue.Text = variableValue;
|
}
|
else
|
{
|
|
}
|
}
|
catch
|
{
|
}
|
}
|
|
private void tbxCommandName_TextChanged(object sender, TextChangedEventArgs e)
|
{
|
try
|
{
|
if (methodSetVariable != null)
|
{
|
methodSetVariable.name = tbxCommandName.Text;
|
}
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
}
|
|
private void tbxVariableValue_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
{
|
string integerPattern = @"^-?\d+$";
|
string decimalPattern = @"^-?\d+(\.\d+)?$";
|
string postfix = "";
|
if (e.Text == "-")
|
{
|
postfix = "0";
|
}
|
|
Regex regex = new Regex(integerPattern);
|
bool integerPatternBool= regex.IsMatch(tbxVariableValue.Text+e.Text+ postfix);
|
regex = new Regex(decimalPattern);
|
|
bool decimalPatternBool = regex.IsMatch(tbxVariableValue.Text + e.Text+ postfix);
|
if (e.Text==".")
|
{
|
decimalPatternBool = regex.IsMatch(tbxVariableValue.Text + e.Text+"0");
|
}
|
else
|
{
|
|
}
|
|
|
if (!integerPatternBool && !decimalPatternBool)
|
{
|
tbxVariableValue.Text = "";
|
e.Handled = true;
|
}
|
}
|
|
private void tbxVariableName_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
{
|
Regex regex = new Regex(@"^[a-zA-Z][a-zA-Z0-9_]*$");
|
if (!regex.IsMatch(tbxVariableName.Text+e.Text))
|
{
|
tbxVariableName.Text = "";
|
e.Handled = true;
|
}
|
}
|
}
|
}
|