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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
using CommunityToolkit.Mvvm.Input;
using FLY.Thick.Base.IService;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Unity;
namespace FLY.Thick.Base.UI
{
/// <summary>
/// Page_GetSample.xaml 的交互逻辑
/// </summary>
public partial class PgGetSample : Page
{
IGetSampleService getSampleService;
IInitParamService initParamService;
PgGetSampleVm viewModel;
public PgGetSample()
{
InitializeComponent();
if (System.ComponentModel.LicenseManager.UsageMode != System.ComponentModel.LicenseUsageMode.Runtime)
return;
this.Loaded += UcGridGraph_Loaded;
this.Unloaded += UcGridGraph_Unloaded;
}
private void UcGridGraph_Unloaded(object sender, RoutedEventArgs e)
{
viewModel.DisposeBinding();
}
private void UcGridGraph_Loaded(object sender, RoutedEventArgs e)
{
viewModel.SetBinding();
}
[InjectionMethod]
public void Init(
IGetSampleService getSampleService,
IInitParamService initParamService,
string infoName = null)
{
this.getSampleService = getSampleService;
this.initParamService = initParamService;
viewModel = new PgGetSampleVm();
viewModel.Init(getSampleService, infoName);
this.DataContext = viewModel;
this.grid_initparam.DataContext = this.initParamService;
}
}
public class PgGetSampleVm : INotifyPropertyChanged
{
#region Markno
const int MARKNO_UPDATE_SAMPLE = 1;
const int MARKNO_UPDATE_FEATURE = 2;
#endregion
#region 参数
/// <summary>
/// 参数:使能
/// </summary>
public bool Enable { get; set; }
/// <summary>
/// 参数:样品点范围
/// </summary>
public int SampleRange { get; set; }
/// <summary>
/// 参数:移动滤波 ,窗口值
/// </summary>
public int Window { get; set; }
/// <summary>
/// 使用%方式检查异常
/// </summary>
public bool IsCheckByPercent { get; set; }
/// <summary>
/// 异常%
/// </summary>
public double ErrPercent { get; set; }
/// <summary>
/// 异常值
/// </summary>
public int ErrValue { get; set; }
/// <summary>
/// 当前 样品X_AD/样品0_AD 与 上一次比较 差异比例 单位不是%
/// </summary>
public double CrossErrPercent { get; set; }
/// <summary>
/// 参数:样品点参数
/// </summary>
public SampleCellView[] Samples { get; set; }
#endregion
#region Command
public RelayCommand ApplyCmd { get; private set; }
#endregion
public event PropertyChangedEventHandler PropertyChanged;
public string InfoName { get; set; }
IGetSampleService getSampleService;
Dictionary<object, List<Misc.BindingOperations.PropertyChangedEventContexts>> bindingConexts = new Dictionary<object, List<Misc.BindingOperations.PropertyChangedEventContexts>>();
/// <summary>
/// 数据已经绑定了
/// </summary>
bool isBinding;
public PgGetSampleVm()
{
ApplyCmd = new RelayCommand(Apply);
}
public void Init(
IGetSampleService getSampleService,
string infoName)
{
InfoName = infoName;
this.getSampleService = getSampleService;
SetBinding();
}
/// <summary>
/// 参数绑定
/// </summary>
public void SetBinding()
{
if (isBinding)
return;
isBinding = true;
//下面全部event保存在bindingConexts
Misc.BindingOperations.StartMarkdownEvents(bindingConexts);
Misc.BindingOperations.SetBinding(this.getSampleService, nameof(this.getSampleService.Enable), this, nameof(Enable));
Misc.BindingOperations.SetBinding(this.getSampleService, nameof(this.getSampleService.SampleRange), this, nameof(SampleRange));
Misc.BindingOperations.SetBinding(this.getSampleService, nameof(this.getSampleService.Window), this, nameof(Window));
Misc.BindingOperations.SetBinding(this.getSampleService, nameof(this.getSampleService.IsCheckByPercent), this, nameof(IsCheckByPercent));
Misc.BindingOperations.SetBinding(this.getSampleService, nameof(this.getSampleService.ErrPercent), this, nameof(ErrPercent));
Misc.BindingOperations.SetBinding(this.getSampleService, nameof(this.getSampleService.ErrValue), this, nameof(ErrValue));
Misc.BindingOperations.SetBinding(this.getSampleService, nameof(this.getSampleService.CrossErrPercent), this, nameof(CrossErrPercent));
Misc.BindingOperations.SetBinding(this.getSampleService, nameof(this.getSampleService.Samples), this,() =>
{
FObjBase.PollModule.Current.Poll_JustOnce(updateSamples, this, MARKNO_UPDATE_SAMPLE);
});
//备份event完毕, 必须关闭记录
Misc.BindingOperations.StopMarkdownEvents();
}
/// <summary>
/// 解除绑定
/// </summary>
public void DisposeBinding()
{
if (!isBinding)//已经解除绑定了
return;
isBinding = false;
//释放全部 event
Misc.BindingOperations.DisposeEventTargetObject(bindingConexts);
}
void updateSamples()
{
var samples = this.getSampleService.Samples;
if (samples == null)
{
Samples = null;
}
else
{
var sampleViews = new SampleCellView[samples.Count()];
for (int i = 0; i < sampleViews.Count(); i++)
{
sampleViews[i] = new SampleCellView() { Name = i.ToString() };
var sampleView = sampleViews[i];
var sample = samples[i];
Misc.BindingOperations.SetBinding(sample, nameof(SampleCell.Enable), sampleView, nameof(SampleCellView.Enable));
Misc.BindingOperations.SetBinding(sample, nameof(SampleCell.JustForCheck), sampleView, nameof(SampleCellView.JustForCheck));
Misc.BindingOperations.SetBinding(sample, nameof(SampleCell.OrgAD), sampleView, nameof(SampleCellView.OrgAD));
Misc.BindingOperations.SetBinding(sample, nameof(SampleCell.Position), sampleView, nameof(SampleCellView.Position));
Misc.BindingOperations.SetBinding(sample, nameof(SampleCell.AD), sampleView, nameof(SampleCellView.AD));
Misc.BindingOperations.SetBinding(sample, nameof(SampleCell.SampleValue), sampleView, nameof(SampleCellView.SampleValue));
}
updateSampleCellViewVisible(sampleViews);
Samples = sampleViews;
for (int i = 0; i < Samples.Count(); i++)
{
var sampleView = Samples[i];
sampleView.PropertyChanged += (s, e) =>
{
if (e.PropertyName == nameof(SampleCellView.Enable))
{
updateSampleCellViewVisible();
}
};
}
}
}
protected void updateSampleCellViewVisible(SampleCellView[] sampleViews)
{
if (sampleViews == null)
return;
for (int i = 0; i < sampleViews.Count(); i++)
{
if (i == 0)
sampleViews[i].IsVisible = true;
else
{
sampleViews[i].IsVisible = sampleViews[i - 1].Enable;
}
}
}
protected void updateSampleCellViewVisible()
{
updateSampleCellViewVisible(Samples);
}
private void Apply()
{
if (!WdPassword.Authorize("GetSample"))
return;
this.getSampleService.Enable = this.Enable;
this.getSampleService.SampleRange = this.SampleRange;
this.getSampleService.Window = this.Window;
this.getSampleService.IsCheckByPercent = this.IsCheckByPercent;
this.getSampleService.ErrPercent = this.ErrPercent;
this.getSampleService.ErrValue = this.ErrValue;
this.getSampleService.CrossErrPercent = this.CrossErrPercent;
for (int i = 0; i < Samples.Count(); i++)
{
var sample_src = this.Samples[i];
var sample_desp = this.getSampleService.Samples[i];
sample_desp.Enable = sample_src.Enable;
sample_desp.JustForCheck = sample_src.JustForCheck;
sample_desp.OrgAD = sample_src.OrgAD;
sample_desp.Position = sample_src.Position;
}
this.getSampleService.SearchRange = 0;
for (int i = 0; i < this.getSampleService.Features.Count(); i++)
{
var feature_desp = this.getSampleService.Features[i];
feature_desp.Enable = false;
}
getSampleService.Apply();
string tit = (string)Application.Current.TryFindResource("str.PgGetSample.ApplySuccessfully");
FLY.ControlLibrary.Window_Tip.Show(tit, null, TimeSpan.FromSeconds(2));
}
}
public class PgGetSampleVmUt : PgGetSampleVm
{
public PgGetSampleVmUt()
{
Samples = new SampleCellView[3];
for (int i = 0; i < Samples.Count(); i++)
{
SampleCellView sampleCell = new SampleCellView() { Name = i.ToString() };
Samples[i] = sampleCell;
}
Enable = true;
Samples[0].Enable = true;
updateSampleCellViewVisible();
}
}
/// <summary>
/// 样品点
/// </summary>
public class SampleCellView : INotifyPropertyChanged
{
/// <summary>
/// 序号
/// </summary>
public string Name { get; set; }
/// <summary>
/// 显示出来
/// </summary>
public bool IsVisible { get; set; }
/// <summary>
/// 参数:使能
/// </summary>
public bool Enable { get; set; }
/// <summary>
/// 参数:只检查不标定
/// </summary>
public bool JustForCheck { get; set; }
/// <summary>
/// 参数:原始AD值
/// </summary>
public int OrgAD { get; set; }
/// <summary>
/// 参数:位置
/// </summary>
public int Position { get; set; }
public int AD { get; set; }
public double SampleValue { get; set; }
#region INotifyPropertyChanged 成员
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
}