schangxiang@126.com
2025-11-04 f5ed29dc26c7cd952d56ec5721a2efc43cd25992
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
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 逻辑判断
        /// <summary>
        /// 逻辑判断
        /// </summary>
        /// <param name="methodNode">装载方法属性节点对象</param>
        /// <returns>-1:有错;0:条件判断未成立;1:条件判断成立</returns>
        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<Variable> stackTem = new Stack<Variable>();//临时存储变量过得对象
            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
    }
}