using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using DataEntity; using XImagingXhandler.XDAL; using XCommon.Log; using HandyControl.Data; using SqlSugar; using XCommon.Tip; using System.CodeDom.Compiler; namespace XHandler.View.MethodProperty { /// /// IfElseProperty.xaml 的交互逻辑 /// public partial class IfElseProperty : UserControl { CodeDomProvider provider = CodeDomProvider.CreateProvider("C#"); public MethodIfElse methodIfElse { get; set; } public MethodIfElse currmethodIfElse = null; public MethodEx method = null; string isrun = ""; string status = ""; string name = ""; string label = ""; string variableName = ""; int condition = 0; string variableValue = ""; int mark = 0; public IfElseProperty() { InitializeComponent(); } public IfElseProperty(MethodEx method) { InitializeComponent(); methodIfElse = new MethodIfElse(); methodIfElse.isrun = "disable"; methodIfElse.status = (method.isEnabled == true ? "enable" : "disable"); methodIfElse.name = method.method_name; methodIfElse.label = method.method_name; methodIfElse.strIndex = method.strIndex; this.method = method; if (method.tag != null) { methodIfElse = (MethodIfElse)method.tag; currmethodIfElse = methodIfElse; isrun = methodIfElse.isrun; status = methodIfElse.status; name = methodIfElse.name; label = methodIfElse.label; condition = (int)methodIfElse.logicCondition; variableName= methodIfElse.variableName; variableValue= methodIfElse.variableValue; } this.DataContext = methodIfElse; } #region 不包含Else选择去除 private void cbkContainElse_Click(object sender, RoutedEventArgs e) { try { } catch(Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } #endregion private void UserControl_Loaded(object sender, RoutedEventArgs e) { mark += 1; try { if(mark>1) { return; } if (!string.IsNullOrEmpty(variableName)) { tbxCommandName.Text = name; tbxVariableName.Text = variableName; tbxConditionValue.Text = variableValue; cbxCondition.SelectedIndex = condition; } else { tbxVariableName.Text = variableName; tbxConditionValue.Text = variableValue; cbxCondition.SelectedIndex = condition; } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } private void tbxCommandName_TextChanged(object sender, TextChangedEventArgs e) { try { if (methodIfElse != null) { methodIfElse.name = tbxCommandName.Text; } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } private void cbxCondition_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (methodIfElse != null) { methodIfElse.logicCondition = (LogicMark)cbxCondition.SelectedIndex; if (this.method != null) { string logicSymbol = string.Empty; if (methodIfElse.logicCondition == LogicMark.Above) { logicSymbol = ">"; } else if (methodIfElse.logicCondition == LogicMark.Below) { logicSymbol = "<"; } else if (methodIfElse.logicCondition == LogicMark.Equal) { logicSymbol = "="; } else if (methodIfElse.logicCondition == LogicMark.Unequal) { logicSymbol = "!="; } else if (methodIfElse.logicCondition == LogicMark.AboveEqual) { logicSymbol = ">="; } else if (methodIfElse.logicCondition == LogicMark.BelowEqual) { logicSymbol = "<="; } this.method.method_Tipcontent = string.Format("{0}{1}{2}", methodIfElse.variableName, logicSymbol, methodIfElse.variableValue); } } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } private void tbxConditionValue_TextChanged(object sender, TextChangedEventArgs e) { try { if (methodIfElse != null) { methodIfElse.variableValue = tbxConditionValue.Text; if (this.method != null) { string logicSymbol = string.Empty; if (methodIfElse.logicCondition == LogicMark.Above) { logicSymbol = ">"; } else if (methodIfElse.logicCondition == LogicMark.Below) { logicSymbol = "<"; } else if (methodIfElse.logicCondition == LogicMark.Equal) { logicSymbol = "="; } else if (methodIfElse.logicCondition == LogicMark.Unequal) { logicSymbol = "!="; } else if (methodIfElse.logicCondition == LogicMark.AboveEqual) { logicSymbol = ">="; } else if (methodIfElse.logicCondition == LogicMark.BelowEqual) { logicSymbol = "<="; } this.method.method_Tipcontent = string.Format("{0}{1}{2}", methodIfElse.variableName, logicSymbol, methodIfElse.variableValue); } } } 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 (methodIfElse != null) { methodIfElse.variableName = tbxVariableName.Text; if (this.method != null) { string logicSymbol = string.Empty; if (methodIfElse.logicCondition == LogicMark.Above) { logicSymbol = ">"; } else if (methodIfElse.logicCondition == LogicMark.Below) { logicSymbol = "<"; } else if (methodIfElse.logicCondition == LogicMark.Equal) { logicSymbol = "="; } else if (methodIfElse.logicCondition == LogicMark.Unequal) { logicSymbol = "!="; } else if (methodIfElse.logicCondition == LogicMark.AboveEqual) { logicSymbol = ">="; } else if (methodIfElse.logicCondition == LogicMark.BelowEqual) { logicSymbol = "<="; } this.method.method_Tipcontent = string.Format("{0}{1}{2}", methodIfElse.variableName, logicSymbol,methodIfElse.variableValue); } } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } } }