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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
using DataEntity.Share;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using XCommon.Log;
using XCore;
using XHandler.Class;
using XHandler.Class.DataEx;
using XImagingXhandler.XDAL;
 
namespace XHandler.View.MethodProperty
{
    /// <summary>
    /// GripMoveProperty.xaml 的交互逻辑
    /// </summary>
    public partial class GripMoveProperty : UserControl, IMethodProperty
    {
        public MethodGripMove methodGripMove { get; set; }
        public MethodGripMove currmethodGripMove = null;
 
        AspirateBll aspirateBll = new AspirateBll();
        List<Lattice> lattices = new List<Lattice>();
        int curArmSelectedIndex = -1;
        int curLatticeSelectedIndex = -1;
 
        #region 全局属性变量
        string isrun = "";
        string status = "";
        string name = "";
        string label = "";
        string armText = "";
        string armValue = "";
        string latticeText = "";
        string latticeValue = "";
        int mark = 0;
        #endregion
 
        public GripMoveProperty()
        {
            InitializeComponent();
        }
 
        public GripMoveProperty(MethodEx method)
        {
            InitializeComponent();
            mark = 0;
            curArmSelectedIndex = 0;
            curLatticeSelectedIndex = 0;
 
            List<DeviceArm> deviceArms = aspirateBll.ProviderDeviceArmList();
            cbArm.ItemsSource = deviceArms;
            if (deviceArms.Count == 2) //只有一个臂的情况下默认选中该臂
                curArmSelectedIndex = 1;
            else
                curArmSelectedIndex = 0;
 
            //lattices = aspirateBll.ProviderLatticeList(Shared.SoftwareInformation.software_device_number, Convert.ToInt32(cbArm.SelectedValue));
            //cbLattice.ItemsSource = lattices;
 
            methodGripMove = new MethodGripMove();
            methodGripMove.name = method.method_name;
            methodGripMove.label = method.method_name;
            methodGripMove.status = (method.isEnabled == true ? "enable" : "disable");
            methodGripMove.strIndex = method.strIndex;
            this.DataContext = methodGripMove;
            if (method.tag != null)
            {
                methodGripMove = (MethodGripMove)method.tag;
 
                currmethodGripMove = methodGripMove;
                isrun = methodGripMove.isrun;
                status = methodGripMove.status;
                name = methodGripMove.name;
                label = methodGripMove.label;
                armText = methodGripMove.armText;
                armValue = methodGripMove.armValue;
                latticeText = methodGripMove.latticeText;
                latticeValue = methodGripMove.latticeValue;
            }
        }
 
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            mark += 1;
            try
            {
                if (mark > 1)
                {
                    return;
                }
                if (!string.IsNullOrEmpty(armText))
                {
                    tbxCommandName.Text = name;
                    cbArm.SelectedValue = armValue;
                    cbLattice.SelectedValue = latticeValue;
 
                    if (currmethodGripMove != null)
                    {
                        methodGripMove = currmethodGripMove;
                    }
                }
                else
                {
                    cbArm.SelectedIndex = curArmSelectedIndex;
                    cbLattice.SelectedIndex = curLatticeSelectedIndex;
 
                    if (currmethodGripMove != null)
                    {
                        methodGripMove = currmethodGripMove;
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
 
        private void cbArm_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (cbArm.SelectedIndex < 0)
                return;
 
            curArmSelectedIndex = cbArm.SelectedIndex;
            DeviceArm arm = cbArm.SelectedItem as DeviceArm;
            if (methodGripMove != null)
            {
                methodGripMove.armText = arm.device_arm_name;
                methodGripMove.armValue = arm.device_arm_id.ToString();
            }
 
            lattices = aspirateBll.ProviderLatticeList(Shared.SoftwareInformation.software_device_number, Convert.ToInt32(cbArm.SelectedValue));
            cbLattice.ItemsSource = lattices;
        }
 
        private void cbLattice_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if(cbLattice.SelectedIndex < 0) 
                return;
 
            curLatticeSelectedIndex= cbLattice.SelectedIndex;
            if(curLatticeSelectedIndex>0)
            {
                Lattice l = cbLattice.SelectedItem as Lattice;
                if (methodGripMove != null)
                {
                    methodGripMove.latticeText = l.lattice_num;
                    methodGripMove.latticeValue = l.lattice_id;
                }
            }
        }
 
        public void SetTableName(string name, Labware labware)
        {
            TextBox tb = Utilities.FindVisualChild<TextBox>(cbLattice);
            if (tb.IsFocused)
            {
                Lattice l = lattices.Find(s => s.lattice_num == name);
                cbLattice.SelectedItem = l;
            }
        }
 
        private void tbxCommandName_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (methodGripMove != null)
                {
                    methodGripMove.name = tbxCommandName.Text;
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.ErrorLog("ERROR:", ex);
            }
        }
    }
}