using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using XHandler.View; using XCore; using XImagingXhandler.XDAL; using System.Xml; using System.Windows.Threading; using DriverLibrary; using System.Windows; using XCommon.Log; using System.Reflection; using XHandler.View.MethodProperty; using static HxEnum.OperationTypeEnum; namespace XHandler.Controls { public class IfElseControl { string strCurrentCulture = ""; public RunWnd launchView = null; public IfElseControl(string strCurrentCulture) { this.strCurrentCulture = strCurrentCulture; } #region 逻辑判断 /// /// 逻辑判断 /// /// 装载方法属性节点对象 /// -1:有错;0:条件判断未成立;1:条件判断成立 public int ExecuteIfElse(XmlNode methodNode) { int iresult = -1; if (launchView._cancelSource.IsCancellationRequested) { iresult = -1; return iresult; } if (strCurrentCulture.Equals("zh-CN")) { launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strStart.ToString()); } else { launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】> Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】start:"); } string variableName = methodNode.SelectSingleNode("variableName").InnerText; int variableValue = Convert.ToInt32(methodNode.SelectSingleNode("variableValue").InnerText); int logicMark= Convert.ToInt32(methodNode.SelectSingleNode("logicCondition").InnerText); Variable variable = new Variable(); Stack stackTem = new Stack();//临时存储变量过得对象 int totalLoop = launchView.gloadVariable.Count; // 从当前变量字典中取出变量的值 for (int i = 0; i < totalLoop; i++) { Variable v = launchView.gloadVariable.Pop(); //取出最近的一个匹配变量 stackTem.Push(v); if (v.variablename == variableName) { variable = v; break; } } int totalLoopTem = stackTem.Count; for (int i=0;i< totalLoopTem; i++) { Variable v = stackTem.Pop(); launchView.gloadVariable.Push(v); } bool result = true; string strLogic = ""; if (variable.variablename!=null&&variable.variablename!="") { switch (logicMark) { case (int)LogicMark.Above: result = (Convert.ToInt32(variable.variablecurval) > variableValue) ? true : false; strLogic = ">"; break; case (int)LogicMark.Below: result = (Convert.ToInt32(variable.variablecurval) < variableValue) ? true : false; strLogic = "<"; break; case (int)LogicMark.Equal: result = (Convert.ToInt32(variable.variablecurval) == variableValue) ? true : false; strLogic = "="; break; case (int)LogicMark.Unequal: result = (Convert.ToInt32(variable.variablecurval) != variableValue) ? true : false; strLogic = "!="; break; case (int)LogicMark.AboveEqual: result = (Convert.ToInt32(variable.variablecurval) >= variableValue) ? true : false; strLogic = ">="; break; case (int)LogicMark.BelowEqual: result = (Convert.ToInt32(variable.variablecurval) <= variableValue) ? true : false; strLogic = "<="; break; default: break; } } else //条件判断的变量没有找到 { if (strCurrentCulture.Equals("zh-CN")) { launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strError.ToString() + Properties.IfElseResource.strNotFindVariable.ToString()); } else { launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】error: there isn't find logic variable."); } iresult = -1; return iresult; } if(!result) { iresult = 0; if (strCurrentCulture.Equals("zh-CN")) { launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.IfElseResource.strConditionFailed.ToString() + " " + variable.variablename + strLogic + variableValue); } else { launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress: logic executing was failed." + " " + variable.variablename + strLogic + variableValue); } } else { iresult = 1; if (strCurrentCulture.Equals("zh-CN")) { launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.IfElseResource.strConditionPass.ToString() +" "+ variable.variablename+ strLogic + variableValue); } else { launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress: logic executing is pass." + " " + variable.variablename + strLogic + variableValue); } if (strCurrentCulture.Equals("zh-CN")) { launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】" + Properties.MachineRunResource.strProgress.ToString() + Properties.IfElseResource.strEnterExecute.ToString()); } else { launchView.AddLogs("【" + DateTime.Now.ToString("HH:mm:ss:fff") + "】>Xhandler: 【" + methodNode.SelectSingleNode("name").InnerText + "】progress: enter execute;"); } } return iresult; } #endregion } }