using System; using System.Windows; using System.Windows.Controls; using XCommon.Log; using XHandler.Class.DataEx; using XImagingXhandler.XDAL; namespace XHandler.View.MethodProperty { /// /// LoopProperty.xaml 的交互逻辑 /// public partial class LoopProperty : UserControl { public MethodLoop methodLoop { get; set; } public MethodEx method = null; public LoopProperty() { InitializeComponent(); } public LoopProperty(MethodEx method) { InitializeComponent(); methodLoop = new MethodLoop(); methodLoop.isrun = "disable"; methodLoop.status = (method.isEnabled == true ? "enable" : "disable"); methodLoop.name = method.method_name; methodLoop.label = method.method_name; methodLoop.strIndex = method.strIndex; this.DataContext = methodLoop; this.method = method; if (method.tag != null) { methodLoop = (MethodLoop)method.tag; } } private void tbxName_TextChanged(object sender, TextChangedEventArgs e) { try { if (methodLoop != null) { methodLoop.name = tbxName.Text; } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } private void tbxVariableName_TextChanged(object sender, TextChangedEventArgs e) { try { if (!Consumables.ConsumablesValidationRule.IsNullOrEmpty(tbxVariableName.Text, out string message)) { xvnError.Text = message; return; } else { xvnError.Text = ""; } if (methodLoop != null) { methodLoop.variableName = tbxVariableName.Text; } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } private void tbxStartValue_TextChanged(object sender, TextChangedEventArgs e) { try { if (!Consumables.ConsumablesValidationRule.IsPositiveIntegerr(tbxStartValue.Text, out string message)) { xsvError.Text = message; return; } else { xsvError.Text = ""; } if (methodLoop != null) { methodLoop.variablesValue = tbxStartValue.Text; if (this.method != null) { this.method.method_Tipcontent = string.Format("从{0}到{1},递增{2}", methodLoop.variablesValue.ToString(), methodLoop.variableeValue.ToString(), methodLoop.incrementValue.ToString()); } } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } private void tbxEndValue_TextChanged(object sender, TextChangedEventArgs e) { try { if (!Consumables.ConsumablesValidationRule.IsPositiveIntegerr(tbxEndValue.Text, out string message)) { xevError.Text = message; return; } else if (Convert.ToInt32(tbxStartValue.Text) > Convert.ToInt32(tbxEndValue.Text)) { xevError.Text = "结束值需大于开始值"; return; } else { xevError.Text = ""; } if (methodLoop != null) { methodLoop.variableeValue = tbxEndValue.Text; if (this.method != null) { this.method.method_Tipcontent = string.Format("从{0}到{1},递增{2}", methodLoop.variablesValue.ToString(), methodLoop.variableeValue.ToString(), methodLoop.incrementValue.ToString()); } } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } private void tbxIncrement_TextChanged(object sender, TextChangedEventArgs e) { try { if (!Consumables.ConsumablesValidationRule.IsPositiveIntegerr(tbxIncrement.Text, out string message)) { xiError.Text = message; return; } //else if ((Convert.ToInt32(tbxStartValue.Text) + Convert.ToInt32(tbxIncrement.Text)) > Convert.ToInt32(tbxEndValue.Text)) //{ // xiError.Text = "开始值+增量不能大于结束值"; // return; //} else { xiError.Text = ""; } if (methodLoop != null) { methodLoop.incrementValue = tbxIncrement.Text; if (this.method != null) { this.method.method_Tipcontent = string.Format("从{0}到{1},递增{2}", methodLoop.variablesValue.ToString(), methodLoop.variableeValue.ToString(), methodLoop.incrementValue.ToString()); } } } catch (Exception ex) { LoggerHelper.ErrorLog("ERROR:", ex); } } private void UserControl_Loaded(object sender, RoutedEventArgs e) { if (!string.IsNullOrEmpty(methodLoop.variableName)) { tbxName.Text = methodLoop.name; tbxVariableName.Text = methodLoop.variableName; tbxStartValue.Text = methodLoop.variablesValue; tbxEndValue.Text = methodLoop.variableeValue; tbxIncrement.Text = methodLoop.incrementValue; } else { } } } }