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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
using DataEntity.Share;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using XImagingXhandler.XDAL;
using DataGrid = System.Windows.Controls.DataGrid;
using TextBox = System.Windows.Controls.TextBox;
 
namespace XHandler.View.MethodProperty
{
    /// <summary>
    /// 补充目标板时输入条码界面
    /// </summary>
    public partial class SetBarcodeDlgForAddConsumables : Window
    {
        /// <summary>
        /// 运行界面
        /// </summary>
        public RunWnd launchView = null;
 
        /// <summary>
        /// 文件涂布数据
        /// </summary>
        public DataTable dtCoatingFile = null;
 
        /// <summary>
        /// 目标板编号开始替换Index
        /// </summary>
        public int StartIndex = 0;
 
        /// <summary>
        /// 输入的条码数据
        /// </summary>
        private ObservableCollection<InputBarcode> inputDatas = new ObservableCollection<InputBarcode>();
 
        /// <summary>
        /// 提示消息内容
        /// </summary>
        private string msg = string.Empty;
 
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="msg"></param>
        public SetBarcodeDlgForAddConsumables(string strMsg)
        {
            InitializeComponent();
            msg = strMsg;
            this.Owner = (Window)Shared.Main;
        }
 
        /// <summary>
        /// 初始化事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // 初始化控件
            InitControl(msg);
        }
 
        private bool IsOnBatch(bool isNewPlateBatch, int iChoiceIndex, int iStartIndex)
        {
            if (isNewPlateBatch)
            {
                if ((launchView.choiceTimes == 1 || launchView.choiceTimes == 2) && (iChoiceIndex == StartIndex))
                {
                    return true;
                }
                else if (launchView.choiceTimes == 2 && (iChoiceIndex == StartIndex + 1))
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return true;            
            }
        }
 
        /// <summary>
        /// 初始化控件
        /// </summary>
        /// <param name="msg"></param>
        private void InitControl(string msg)
        {
            List<string> lstLatticeNum = new List<string>();
            if (dtCoatingFile != null)
            {
                for (int iChoiceIndex = StartIndex; iChoiceIndex < dtCoatingFile.Rows.Count; iChoiceIndex++)
                {
                    string strDesPlateName = dtCoatingFile.Rows[iChoiceIndex]["TargetB"].ToString();
                    string strTargetBarcode = dtCoatingFile.Rows[iChoiceIndex]["TargetBarcode"].ToString();
                    bool isNewPlateBatch = bool.Parse(dtCoatingFile.Rows[iChoiceIndex]["IsNewPlateBatch"].ToString());
                    if (!IsOnBatch(isNewPlateBatch, iChoiceIndex, StartIndex))
                    {
                        break;
                    }
 
                    if (!lstLatticeNum.Contains(strDesPlateName))
                    {
                        lstLatticeNum.Add(strDesPlateName);
                        inputDatas.Add(new InputBarcode()
                        {
                            lattice_num = strDesPlateName,
                            targetplate_barcode = strTargetBarcode
                        });
                    }
                }
            }
 
            dgInputBarcode.DataContext = inputDatas;
            dgInputBarcode.ItemsSource = inputDatas;
            textblockMsg.Text = msg;
        }
 
        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (dtCoatingFile != null)
            {
                for (int iChoiceIndex = StartIndex; iChoiceIndex < dtCoatingFile.Rows.Count; iChoiceIndex++)
                {
                    string strDesPlateName = dtCoatingFile.Rows[iChoiceIndex]["TargetB"].ToString();
                    bool isNewPlateBatch = bool.Parse(dtCoatingFile.Rows[iChoiceIndex]["IsNewPlateBatch"].ToString());
                    if (!IsOnBatch(isNewPlateBatch, iChoiceIndex, StartIndex))
                    {
                        break;
                    }
 
                    InputBarcode brcodeItem = inputDatas.FirstOrDefault(it => it.lattice_num.Equals(strDesPlateName));
                    if (brcodeItem != null)
                    {
                        dtCoatingFile.Rows[iChoiceIndex]["TargetBarcode"] = brcodeItem.targetplate_barcode;
                    }
                }
            }
 
            DialogResult = true;
        }
 
        /// <summary>
        /// 关闭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
 
        #region DataGrid事件
        private void dgCoatingData_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            //如果点击了放弃按钮或ESC
            if (e.EditAction == DataGridEditAction.Cancel)
            {
                return;
            }
            //获取编辑模式显示的元素,因为使用了模板,因此这里是ContentPresenter类型
            ContentPresenter cp = e.EditingElement as ContentPresenter;
            if (cp != null && VisualTreeHelper.GetChildrenCount(cp) > 0)
            {
                //找到编辑框
                TextBox textBox = VisualTreeHelper.GetChild(cp, 0) as TextBox;
                //如果找到
                if (textBox != null)
                {
                    var a = inputDatas;
 
                    var dataGrid = sender as DataGrid;
                    dataGrid.BeginEdit();
                }
            }
        }
 
        private void DataGridCell_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (e.OriginalSource is System.Windows.Shapes.Path)
            {
                Cursor = Cursors.Cross;
            }
            else
            {
                Cursor = Cursors.Arrow;
            }
        }
 
        private void DataGridCell_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            Debug.WriteLine("Double click");
            DataGridCell cell = sender as DataGridCell;
            if ((cell.Column.DisplayIndex == 1) || (cell.Column.DisplayIndex == 2) || (cell.Column.DisplayIndex == 5)
                || (cell.Column.DisplayIndex == 6) || (cell.Column.DisplayIndex == 7))
            {
                cell.Column.IsReadOnly = false;
            }
            cell.Focus();
            cell.IsSelected = true;
            dgInputBarcode.BeginEdit();
            e.Handled = true;
        }
        #endregion
 
        #region 拖动窗体
        /// <summary>
        /// 拖动窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
            {
                this.DragMove();
            }
        }
        #endregion
    }
}