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
using System.Collections.Generic;
using System.Windows.Media;
using System.Windows;
using System;
using HandyControl.Data;
using HxEnum;
using XCommon.Tip;
using XImagingXhandler.XDAL;
using XHandler.View.MethodProperty;
using System.Windows.Controls;
using DataEntity.Share;
using System.Collections.ObjectModel;
using System.Linq;
using XCore;
 
namespace XHandler.View.Com
{
    /// <summary>
    /// 视图共用类
    /// </summary>
    public class ViewCom
    {
        #region 查找控件的子控件,并返回子控件对象
        public static List<T> GetChildObjects<T>(DependencyObject obj, Type typename) where T : FrameworkElement
        {
            DependencyObject child = null;
            List<T> childList = new List<T>();
 
            for (int i = 0; i <= VisualTreeHelper.GetChildrenCount(obj) - 1; i++)
            {
                child = VisualTreeHelper.GetChild(obj, i);
 
                if (child is T && (((T)child).GetType() == typename))
                {
                    childList.Add((T)child);
                }
                childList.AddRange(GetChildObjects<T>(child, typename));
            }
            return childList;
        }
        #endregion
 
        #region 打开子方法流程状态页面
        /// <summary>
        /// 打开子方法流程状态页面
        /// </summary>
        /// <param name="mEx"></param>
        /// <param name="IsStart"></param>
        public static void OpenSubMethodWorkflow(TreeView runTreeviewWorkflow)
        {
            if (runTreeviewWorkflow.SelectedItem == null)
            {
                return;
            }
 
            MethodEx mEx = runTreeviewWorkflow.SelectedItem as MethodEx;
            if (mEx.tag == null)
            {
                return;
            }
 
            // 不是子方法,无法查看
            int iNum = new MethodListBll().getNumByMethodName(mEx.method_name);
            if (!iNum.Equals((int)(MethodNameEnum.subMethod)))
            {
                ShowTip.ShowNotice("不是子方法,无法查看", InfoType.Warning);
                return;
            }
 
            MethodSubMethod method = (MethodSubMethod)mEx.tag;
            SubMethodWorkflow subMethodWorkflow = new SubMethodWorkflow(method);
            subMethodWorkflow.Show();
        }
        #endregion
 
        #region 初始化工作流
        /// <summary>
        /// 初始化工作流
        /// </summary>
        /// <param name="rootMethod"></param>
        public static void InitWorkFlow(MethodEx rootMethod)
        {
            // 获取方法指令集合
            ObservableCollection<Method> methods = MethodDB.GetMethodFromdb(Shared.SoftwareInformation.software_device_number);
 
            // 获取固定方法节点
            var selFixMethod = methods.Where(s => s.method_group_id == EnumManagement.GetEnumValue(MethodGroupEnum.None)).OrderBy(s => s.method_id);
            rootMethod.method_name = "root";
            rootMethod.Level = -1;
 
            if (!selFixMethod.Any())
            {
                return;
            }
 
            List<Method> fixMethodList = selFixMethod.ToList();
            for (int index = 0; index < fixMethodList.Count; index++)
            {
                Method fixMethodItem = fixMethodList[index];
                MethodEx mEx = new MethodEx(fixMethodItem, rootMethod);
                mEx.Index = rootMethod.Children.Count + 1;
                mEx.strIndex = mEx.Index.ToString();
                mEx.Moveable = false;
 
                // 可往台面布置内拖动
                mEx.canDrop = mEx.method_id.Equals("1");
 
                rootMethod.Children.Add(mEx);
                if (mEx.method_id == "0")        // 开始
                {
                    StartProperty property = new StartProperty(mEx);
                    mEx.control = property;
                }
                else if (mEx.method_id == "2")   // 结束
                {
                    EndProperty property = new EndProperty(mEx);
                    mEx.control = property;
                }
            }
        }
        #endregion
 
        #region MethodEx重新排序号
        /// <summary>
        /// MethodEx重新排序号
        /// </summary>
        /// <param name="index"></param>
        /// <param name="mEx"></param>
        public static void ReOrderMethodIndex(string index, MethodEx mEx)
        {
            int subIndex = 1;
            foreach (var mExItem in mEx.Children)
            {
                mExItem.Index = subIndex;
                mExItem.Level = mEx.Level + 1;
                if (mExItem.Level == 0)
                {
                    mExItem.strIndex = subIndex.ToString();
                }
                else
                {
                    mExItem.strIndex = index + "-" + subIndex;
                }
                ReOrderMethodIndex(mExItem.strIndex, mExItem);
                subIndex++;
            }
        }
        #endregion
    }
}