liuye
authored
|
1
2
3
4
|
#include "stdafx.h"
#include "etrade_edit_control.h"
#include "resource.h"
#include "place_order_dlg.h"
|
liuye
authored
|
5
6
7
|
#include "etradeclient/utility/win_http.h"
#include "etradeclient/utility/logging.h"
#include "ETradeClient/utility/win_msg_define.h"
|
liuye
authored
|
8
|
|
liuye
authored
|
9
10
|
IMPLEMENT_DYNAMIC( CEditBox, CMFCMaskedEdit )
|
liuye
authored
|
11
12
13
|
CEditBox::CEditBox()
{
|
liuye
authored
|
14
|
m_clrFrame = RGB( 245, 108, 108 );
|
liuye
authored
|
15
|
is_edit_red_ = false;
|
liuye
authored
|
16
|
check_type_ = DoNotCheck;
|
liuye
authored
|
17
18
19
20
21
22
|
}
CEditBox::~CEditBox()
{
}
|
liuye
authored
|
23
|
BEGIN_MESSAGE_MAP(CEditBox, CEdit)
|
liuye
authored
|
24
25
|
ON_WM_NCPAINT()
ON_WM_KILLFOCUS()
|
liuye
authored
|
26
|
ON_WM_CHAR()
|
liuye
authored
|
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
|
END_MESSAGE_MAP()
void CEditBox::OnNcPaint()
{
CEdit::OnNcPaint();
if (is_edit_red_)
{
CRect rcEdit;
CBrush brushOut;
CDC *pDC = GetWindowDC();
GetWindowRect(rcEdit);
ScreenToClient(&rcEdit);
rcEdit.OffsetRect(CSize(2, 2));
brushOut.CreateSolidBrush(m_clrFrame);
pDC->FrameRect(rcEdit, &brushOut);
ReleaseDC(pDC);
}
}
void CEditBox::OnKillFocus(CWnd* pNewWnd)
{
CEdit::OnKillFocus(pNewWnd);
int dlg_id = GetDlgCtrlID();
|
liuye
authored
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
GetParent()->SendMessage(WM_ORDER_KILL_FOCUS, dlg_id);
}
void CEditBox::SetEditRed(bool is_red)
{
is_edit_red_ = is_red;
UpdateWindow();
}
void CEditBox::SetCheck(CheckType type)
{
check_type_ = type;
}
|
liuye
authored
|
70
|
|
liuye
authored
|
71
72
73
|
void CEditBox::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (check_type_ == DoNotCheck || nChar < 32 || nChar > 126)
|
liuye
authored
|
74
|
{
|
liuye
authored
|
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
CEdit::OnChar(nChar, nRepCnt, nFlags);
return;
}
CString sBefore, sAfter;
GetWindowText(sBefore);
//保存光标位置
int nPosCurbgn, nPosCurend;
GetSel(nPosCurbgn, nPosCurend);
CEdit::OnChar(nChar, nRepCnt, nFlags);
GetWindowText(sAfter);
bool result = true;
switch (check_type_)
|
liuye
authored
|
89
|
{
|
liuye
authored
|
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
|
case CardNumType:
{
result = CheckCardNum(sAfter);
break;
}
case CommNumType:
{
result = CheckCommNum(sAfter);
break;
}
case UnitType:
{
result = CheckUnitNum(sAfter);
break;
}
case HeavyType:
{
result = CheckHeavy(sAfter);
break;
}
case PriceType:
{
result = CheckPrice(sAfter);
break;
}
case CountType:
{
result = CheckCount(sAfter);
break;
}
}
if (!result)
{
SetWindowText(sBefore);
SetSel(nPosCurbgn, nPosCurend, true);
}
}
bool CEditBox::CheckCardNum(CString num)
{
bool result = true;
do
{
|
liuye
authored
|
135
|
/*if (num.GetLength() > 12)
|
liuye
authored
|
136
|
{
|
liuye
authored
|
137
138
139
|
result = false;
break;
}*/
|
liuye
authored
|
140
141
|
if (num.SpanIncluding(L"0123456789") != num)
|
liuye
authored
|
142
|
{
|
liuye
authored
|
143
144
|
result = false;
break;
|
liuye
authored
|
145
|
}
|
liuye
authored
|
146
|
} while (0);
|
liuye
authored
|
147
|
|
liuye
authored
|
148
149
|
return result;
}
|
liuye
authored
|
150
|
|
liuye
authored
|
151
152
153
154
155
|
bool CEditBox::CheckCommNum(CString num)
{
bool result = true;
do
|
liuye
authored
|
156
|
{
|
liuye
authored
|
157
158
159
160
161
|
if (num.GetLength() > 3)
{
result = false;
break;
}
|
liuye
authored
|
162
|
|
liuye
authored
|
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
if (num.SpanIncluding(L"0123456789") != num)
{
result = false;
break;
}
} while (0);
return result;
}
bool CEditBox::CheckUnitNum(CString num)
{
bool result = true;
if (num.Compare(L"1") != 0 && num.Compare(L"2") != 0)
{
result = false;
|
liuye
authored
|
180
|
}
|
liuye
authored
|
181
182
|
return result;
|
liuye
authored
|
183
184
|
}
|
liuye
authored
|
185
|
bool CEditBox::CheckHeavy(CString heavy)
|
liuye
authored
|
186
187
188
189
190
|
{
bool result = true;
do
{
|
liuye
authored
|
191
192
|
int length = heavy.GetLength();
if (length > 8)
|
liuye
authored
|
193
194
195
196
197
|
{
result = false;
break;
}
|
liuye
authored
|
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
if (heavy.SpanIncluding(L"0123456789.") != heavy)
{
result = false;
break;
}
double num = _ttof(heavy);
if (num > 100000)
{
result = false;
break;
}
//如果精度超过设置的精度则返回
int dec_pos = heavy.Find(L".");
if (dec_pos != CB_ERR && length - dec_pos - 1 > 1)
|
liuye
authored
|
214
215
216
217
|
{
result = false;
break;
}
|
liuye
authored
|
218
219
220
221
222
223
|
//小数点不在首位
if (length > 0 && heavy.Left(1) == ".")
{
result = false;
break;
}
|
liuye
authored
|
224
225
226
227
228
229
230
231
232
233
234
|
//首位为0时,次首位只能是小数点
if (length == 2 && heavy.Left(1) == "0")
{
if (heavy.Right(1) != ".")
{
result = false;
break;
}
}
|
liuye
authored
|
235
236
237
238
239
240
241
|
//只有一个小数点
if (heavy.Replace(L".", L".") > 1)
{
result = false;
break;
}
|
liuye
authored
|
242
|
} while (0);
|
liuye
authored
|
243
244
245
246
247
248
249
|
return result;
}
bool CEditBox::CheckPrice(CString price)
{
bool result = true;
|
liuye
authored
|
250
|
|
liuye
authored
|
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
|
do
{
int length = price.GetLength();
if (length > 8)
{
result = false;
break;
}
if (price.SpanIncluding(L"0123456789.") != price)
{
result = false;
break;
}
double num = _ttof(price);
if (num > 50000)
{
result = false;
break;
}
//如果精度超过设置的精度则返回
int dec_pos = price.Find(L".");
if (dec_pos != CB_ERR && length - dec_pos - 1 > 2)
{
result = false;
break;
}
//小数点不在首位
if (length > 0 && price.Left(1) == ".")
{
result = false;
break;
}
|
liuye
authored
|
286
287
288
289
290
291
292
293
294
295
296
|
//首位为0时,次首位只能是小数点
if (length == 2 && price.Left(1) == "0")
{
if (price.Right(1) != ".")
{
result = false;
break;
}
}
|
liuye
authored
|
297
298
299
300
301
302
303
304
305
|
//只有一个小数点
if (price.Replace(L".", L".") > 1)
{
result = false;
break;
}
} while (0);
|
liuye
authored
|
306
307
308
|
return result;
}
|
liuye
authored
|
309
|
bool CEditBox::CheckCount(CString count)
|
liuye
authored
|
310
311
312
|
{
bool result = true;
|
liuye
authored
|
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
|
do
{
int length = count.GetLength();
if (length > 8)
{
result = false;
break;
}
if (count.SpanIncluding(L"0123456789.") != count)
{
result = false;
break;
}
double num = _ttof(count);
if (num > 100000)
{
result = false;
break;
}
//如果精度超过设置的精度则返回
int dec_pos = count.Find(L".");
if (dec_pos != CB_ERR && length - dec_pos - 1 > 1)
{
result = false;
break;
}
//小数点不在首位
if (length > 0 && count.Left(1) == ".")
{
result = false;
break;
}
//只有一个小数点,这里有个坑,必须用L".",不能用'.',否则始终返回0
if (count.Replace(L".", L".") > 1)
{
result = false;
break;
}
|
liuye
authored
|
354
|
|
liuye
authored
|
355
|
} while (0);
|
liuye
authored
|
356
357
358
359
|
return result;
}
|
liuye
authored
|
360
|
bool CEditBox::IsEditRed()
|
liuye
authored
|
361
|
{
|
liuye
authored
|
362
|
return is_edit_red_;
|
liuye
authored
|
363
|
}
|