Project

General

Profile

Feature #580 » ToolView.cpp

yufeng wu, 06/07/2020 08:48 PM

 
1
// ToolView.cpp : implementation file
2
//
3

    
4
#include "stdafx.h"
5
#include "in_hevt.h"
6
#include "mainfrm.h"
7
//#include "Ehhevtdoc.h"
8

    
9
#include "Ehhevtview.h"
10

    
11
#include "ToolView.h"
12
#include "sqlstmt.h"
13
#ifdef _DEBUG
14
#define new DEBUG_NEW
15
#undef THIS_FILE
16
static char THIS_FILE[] = __FILE__;
17
#endif
18

    
19
/////////////////////////////////////////////////////////////////////////////
20
// CToolView
21

    
22
//IMPLEMENT_DYNCREATE(CToolView, CFormView)
23

    
24
void IdleTheCpu(DWORD dwMilliSeconds)
25
{
26
    MSG msg;
27
    if ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) )
28
    {
29
        TranslateMessage(&msg);
30
        DispatchMessage(&msg);
31
    }
32
    Sleep(dwMilliSeconds);
33
}
34

    
35
CToolView::CToolView()
36
//	: CFormView(CToolView::IDD)
37
{
38
	//{{AFX_DATA_INIT(CToolView)
39
	m_startTime = 0;
40
	m_endTime = 0;
41
	m_endHour = 0;
42
	m_startHour = 0;
43
	m_nSRadio =-1;
44
	CTime t = CTime::GetCurrentTime();
45
	m_startTime = CTime(t.GetYear(), t.GetMonth(), /*1*/t.GetDay() - 1, 0, 0, 0);//Feature #471 Ĭ??ʱ?????Ե?ǰʱ????ǰ24Сʱ  Weizx 2020-04-10
46
	m_endTime = t;
47
	m_startHour = t;
48
	m_endHour = t;
49
	m_chkGroup = FALSE;
50
	m_chkSys = FALSE;
51
	m_chkDevType = FALSE;
52
	m_chkPrior = FALSE;
53
	m_chkEvtType = FALSE;
54
	m_chkTime = FALSE;
55
	//}}AFX_DATA_INIT
56
	nPageIdx = 0;
57
	m_pMain = NULL;
58
	m_queryThread = NULL;
59
	m_queryNextThread = NULL;
60
	m_stopQueryThreadFlag = FALSE;
61
	IsAlreadyQueryed = false;
62
	m_bBusy = false;
63
	m_nFlags = 0;
64
	m_nSkip = 0;
65
	memset(m_sDiv,0,3);//Added by WYF 20200605
66
}
67

    
68
CToolView::~CToolView()
69
{
70
}
71

    
72
void CToolView::DoDataExchange(CDataExchange* pDX)
73
{
74
	CDialogBar::DoDataExchange(pDX);
75
	//{{AFX_DATA_MAP(CToolView)
76
    DDX_Control(pDX, IDC_BUTTON_DEVICE, m_ctrlDev); //IDC_COMBODEV
77
	DDX_Control(pDX, IDC_COMBOAOJ, m_ctrlAoj);
78
	DDX_Control(pDX, IDC_BUTTON_APPSYS, m_ctrlAppSys);
79
	DDX_Control(pDX, IDC_BUTTON_TYPE, m_ctrlType);
80
	DDX_Control(pDX, IDC_BUTTON_SORT, m_ctrlPrio);
81
	DDX_Control(pDX, IDC_COMBOUSR, m_ctrlUser);
82
	DDX_Control(pDX, IDC_STATIC_USER, m_UserImg);
83
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_startTime);
84
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER2, m_endTime);
85
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER4, m_endHour);
86
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER3, m_startHour);
87
	DDX_Radio(pDX, IDC_RADIO_STA, m_nSRadio);
88
	DDX_Control(pDX, IDC_BUTTON_GROUP, m_ctrlGroup);//wyf 20181008
89
	DDX_Check(pDX, IDC_CHECK_GROUP, m_chkGroup);
90
	DDX_Check(pDX, IDC_CHECK_SYS, m_chkSys);
91
	DDX_Check(pDX, IDC_CHECK_DEVTYPE, m_chkDevType);
92
	DDX_Check(pDX, IDC_CHECK_PRIOR, m_chkPrior);
93
	DDX_Check(pDX, IDC_CHECK_EVTTYPE, m_chkEvtType);
94
	DDX_Check(pDX, IDC_CHECK_TIME, m_chkTime);
95
	//}}AFX_DATA_MAP
96
}
97

    
98
BEGIN_MESSAGE_MAP(CToolView, CDialogBar)
99
	//{{AFX_MSG_MAP(CToolView)
100
	ON_WM_CTLCOLOR()
101
	//ON_WM_PAINT()
102
	ON_BN_CLICKED(IDC_RADIO_STA, OnRadio1)
103
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
104
	ON_BN_CLICKED(IDC_STATION, OnStation)
105
	ON_BN_CLICKED(IDC_QUERY, OnQuery)
106
	//ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
107
	//ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
108
	//ON_COMMAND(IDI_ICON2/*ID_FILE_PRINT_PREVIEW*/, CView::OnFilePrintPreview)
109
	ON_BN_CLICKED(IDC_BTNPRINT, OnBtnPrint)//wyf 20181008
110
	ON_BN_CLICKED(IDC_CHECK_GROUP, OnChkGroup)
111
	ON_BN_CLICKED(IDC_CHECK_SYS, OnChkSys)
112
	ON_BN_CLICKED(IDC_CHECK_DEVTYPE, OnChkDevType)
113
	ON_BN_CLICKED(IDC_CHECK_PRIOR, OnChkPrior)
114
	ON_BN_CLICKED(IDC_CHECK_EVTTYPE, OnChkEvtType)
115
	ON_BN_CLICKED(IDC_CHECK_TIME, OnChkTime)
116
	ON_STN_CLICKED(IDC_STATIC_GROUP, OnStaticGroup)
117
	ON_STN_CLICKED(IDC_STATIC_SYS, OnStaticSys)
118
	ON_STN_CLICKED(IDC_STATIC_DEVTYPE, OnStaticDevType)
119
	ON_STN_CLICKED(IDC_STATIC_PRIOR, OnStaticPrior)
120
	ON_STN_CLICKED(IDC_STATIC_EVTTYPE, OnStaticEvtType)
121
	ON_STN_CLICKED(IDC_STATIC_TIME, OnStaticTime)
122
	ON_WM_LBUTTONDBLCLK()
123
	ON_WM_LBUTTONDOWN()
124
	ON_WM_DRAWITEM()
125
	//ON_WM_SIZE()
126
	//}}AFX_MSG_MAP
127
END_MESSAGE_MAP()
128

    
129
/////////////////////////////////////////////////////////////////////////////
130
// CToolView diagnostics
131

    
132
#ifdef _DEBUG
133
void CToolView::AssertValid() const
134
{
135
	CDialogBar::AssertValid();
136
}
137

    
138
void CToolView::Dump(CDumpContext& dc) const
139
{
140
	CDialogBar::Dump(dc);
141
}
142
#endif //_DEBUG
143

    
144
/////////////////////////////////////////////////////////////////////////////
145
// CToolView message handlers
146
BOOL CToolView::Create(CWnd* pParentWnd, UINT nIDTemplate, UINT nStyle, UINT nID)
147
{
148
	int ret = CDialogBar::Create(pParentWnd, nIDTemplate, nStyle, nID);
149
	OnInitDialog();
150
	return ret;
151
}
152

    
153
HBRUSH CToolView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
154
{	
155
	HBRUSH hbr = CDialogBar::OnCtlColor(pDC, pWnd, nCtlColor);
156
    if(nCtlColor==CTLCOLOR_LISTBOX )
157
	{
158
		pDC->SetTextColor(RGB(255,255,255));
159
		pDC->SetBkColor(g_pApp->m_GridBkColor);
160
		return m_brush1;
161
	}
162
	else if(nCtlColor==CTLCOLOR_EDIT)
163
	{
164
		pDC->SetTextColor(RGB(0,0,0));
165
		pDC->SetBkColor(RGB(255,255,255));
166
		return m_brush2;
167
	}
168
	else if(nCtlColor==CTLCOLOR_DLG )
169
	{
170
		pDC->SetTextColor(RGB(255,255,255));
171
	    pDC->SetBkColor(g_pApp->m_GridBkColor);
172
		CCheckComboBox::HideActiveDropDown();
173
		return m_brush1;
174
	}
175
	else if(nCtlColor==CTLCOLOR_STATIC)
176
	{
177
		pDC->SetTextColor(RGB(255,255,255));
178
	    pDC->SetBkColor(g_pApp->m_GridBkColor);
179
		return m_brush1;
180
	}
181
    return hbr;
182
	
183
}
184

    
185
void CToolView::OnPaint() 
186
{
187
	CPaintDC dc(this); // device context for painting
188
	
189
	// TODO: Add your message handler code here
190
		//??ô??ڴ?С
191
}
192

    
193
void CToolView::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
194
{
195
	if (nIDCtl == IDC_QUERY || nIDCtl == IDC_BTNPRINT)
196
	{
197
		CDC dc;
198
		RECT rect;
199
		dc.Attach(lpDrawItemStruct->hDC);
200
		rect = lpDrawItemStruct->rcItem;   
201
		dc.Draw3dRect(&rect, RGB(255,255,255), RGB(0,0,0));        
202
		UINT state = lpDrawItemStruct->itemState;        
203
		COLORREF fontColor = RGB(0, 0, 0);
204
		COLORREF bkColor = RGB(240, 240, 240);
205
		dc.FillSolidRect(&rect, bkColor);
206
		if ((state & ODS_SELECTED))
207
		{
208
			dc.DrawEdge(&rect, EDGE_SUNKEN, BF_RECT);
209
		}
210
		else
211
		{
212
			dc.DrawEdge(&rect, EDGE_RAISED, BF_RECT);
213
		}
214
		dc.SetBkColor(bkColor);
215
		dc.SetTextColor(fontColor);
216
		TCHAR buffer[MAX_PATH];
217
		ZeroMemory(buffer, MAX_PATH);
218
		::GetWindowText(lpDrawItemStruct->hwndItem, buffer, MAX_PATH);
219
		
220
		dc.DrawText(buffer, &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE);        
221
		dc.Detach();
222
	}
223
	else
224
	{
225
		CDialogBar::OnDrawItem(nIDCtl, lpDrawItemStruct);
226
	}
227
	
228
}
229

    
230
void CToolView::OnInitDialog() 
231
{
232
	IsAlreadyQueryed = FALSE;
233
	//CFormView::OnInitialUpdate();
234
	
235
	// TODO: Add your specialized code here and/or call the base class
236
	if (!UpdateData(FALSE))
237
	{
238
		TRACE0("Waring, Unable to init update.\n");
239
	}
240

    
241
	m_UserImg.SetImage(IDB_BITMAP_USER);
242

    
243
	if (!InitAllData())
244
	{
245
		MessageBox("???ݿ??ѯʧ?ܣ??????˳?", "??ѯʧ??", MB_ICONERROR | MB_OK);
246
		return ;
247
	}
248
	CIn_hevtApp *pApp =(CIn_hevtApp *)AfxGetApp();
249
    InitCombo();
250
    CReadConf cfg;
251
	cfg.ReadString("History", "???ڼ????", m_sDiv, pApp->m_szCfgPath, "-");//Added by WYF 20200605
252
	m_lCount = GetPrivateProfileInt("History", "MaxCount", 5000, pApp->m_szCfgPath);
253
	m_lLimitCount = GetPrivateProfileInt("History", "LimitCount", 10000, pApp->m_szCfgPath);
254
	m_sortOrder = GetPrivateProfileInt("History", "ʱ??????????", 0, pApp->m_szCfgPath);
255
	m_bAlarmClr = (GetPrivateProfileInt("History", "ʹ?ø澯?ȼ???ɫ", 0, pApp->m_szCfgPath) == 0) ? FALSE : TRUE;
256
	if (m_lCount > 5000)
257
	{
258
		m_lCount = 5000;
259
	}
260
	
261
	m_bStation = false;
262
	m_nSRadio =TRUE;
263
	GetDlgItem(IDC_STATION)->EnableWindow(!m_nSRadio);
264
	GetDlgItem(IDC_COMBOUSR)->EnableWindow(m_nSRadio);
265
	((CButton*)GetDlgItem(IDC_RADIO_STA))->SetCheck(m_nSRadio);
266
	((CButton*)GetDlgItem(IDC_RADIO2))->SetCheck(!m_nSRadio);
267
	memset(&m_con, 0, sizeof(CON));
268

    
269
	m_brush1.CreateSolidBrush(RGB(7,54,80));
270
	m_brush2.CreateSolidBrush(RGB(255,255,255));
271
}
272

    
273
BOOL CToolView::InitAllData()
274
{
275
    CSE_DBOption dbo;
276
    CIn_hevtApp *pApp =(CIn_hevtApp *)AfxGetApp();
277
	// -------------------------Init Group------------------------wyf 20181008
278
	if (dbo.BeginSelectRcdSet(SQL_GROUP) != SEDB_SUCCESS)
279
		return FALSE;
280
    int i=0;
281
	int retcount = dbo.GetRcdCount();
282
	if(retcount >0)
283
	{
284
		m_group.SetSize(retcount);
285
		
286
		for ( i = 0; i < retcount; i++)
287
		{
288
			strcpy(m_group[i].szName, dbo.GetStringVal(i, 1));//GroupCode
289
			strcpy(m_group[i].szDesc, dbo.GetStringVal(i, 2));//GroupDesc
290
		}
291
	}
292
	dbo.EndSelectRcdSet();
293

    
294
	// -------------------------Init Priority------------------------
295
	if (dbo.BeginSelectRcdSet(SQL_ALMPRI) != SEDB_SUCCESS)
296
		return FALSE;
297
	retcount = dbo.GetRcdCount();
298
	if(retcount >0)
299
	{
300
		m_priType.SetSize(retcount);
301

    
302
		for ( i = 0; i < retcount; i++)
303
		{
304
			m_priType[i].pri = dbo.GetByteVal(i, 0);
305
			strcpy(m_priType[i].desc, dbo.GetStringVal(i, 1));
306
			m_priType[i].color = dbo.GetUIntVal(i, 2);
307
		}
308
	}
309
	dbo.EndSelectRcdSet();
310

    
311
	// --------------------------Init EType--------------------------
312
	if (dbo.BeginSelectRcdSet(SQL_ALMCLASS) != SEDB_SUCCESS)
313
		return FALSE;
314

    
315
	retcount = dbo.GetRcdCount();
316
	if(retcount >0)
317
	{
318
		m_evtType.SetSize(retcount);
319

    
320
		m_TypeMap.InitHashTable((UINT)(retcount*1.2));
321

    
322
		for (i = 0; i < retcount; i++)
323
		{
324
			strcpy(m_evtType[i].szName, dbo.GetStringVal(i, 0));
325
			strcpy(m_evtType[i].szDesc, dbo.GetStringVal(i, 1));
326

    
327
			m_TypeMap[m_evtType[i].szName] = i;
328
		}
329
	}
330
	dbo.EndSelectRcdSet();
331

    
332
	// --------------------------Init user---------------------------
333
	if (dbo.BeginSelectRcdSet(SQL_USER) != SEDB_SUCCESS)
334
		return FALSE;
335

    
336
	retcount = dbo.GetRcdCount();
337
	if(retcount >0)
338
	{
339
		m_userStr.SetSize(retcount);
340
		m_userDesStr.SetSize(retcount);
341
		for (i = 0; i < retcount; i++)
342
		{
343
			m_userStr[i] = dbo.GetStringVal(i, 1);
344

    
345
			m_userDesStr[i] = dbo.GetStringVal(i, 0);
346
		}
347
	}
348
	dbo.EndSelectRcdSet();
349

    
350
	// --------------------Init DevType------------------------------
351
	if (dbo.BeginSelectRcdSet(SQL_DEVTYPE) != SEDB_SUCCESS)
352
		return FALSE;
353

    
354
	retcount = dbo.GetRcdCount();
355
	if(retcount >0)
356
	{
357
		m_devType.SetSize(retcount);
358

    
359
		m_devMap.InitHashTable((UINT)(retcount*1.2));
360

    
361
		for (i = 0; i < retcount; i++)
362
		{
363
			m_devType[i].sType = dbo.GetByteVal(i, 0);
364
			strcpy(m_devType[i].szDesc, dbo.GetStringVal(i, 1));
365

    
366
			m_devMap[m_devType[i].sType] = i;
367
		}
368
	}
369
	dbo.EndSelectRcdSet();
370

    
371
	// ---------------------Init Aoj---------------------------------
372
	if (dbo.BeginSelectRcdSet(SQL_AOJ) != SEDB_SUCCESS)
373
		return FALSE;
374

    
375
	retcount = dbo.GetRcdCount();
376
	if(retcount >0)
377
	{
378
		m_aojType.SetSize(retcount);
379

    
380
		m_aojMap.InitHashTable((UINT)(retcount*1.2));
381

    
382
		for (i = 0; i < retcount; i++)
383
		{
384
			m_aojType[i].sAoj = dbo.GetByteVal(i, 0);
385
			strcpy(m_aojType[i].szDesc, dbo.GetStringVal(i, 1));
386

    
387
			m_aojMap[m_aojType[i].sAoj] = i;
388
		}
389
	}
390
	dbo.EndSelectRcdSet();
391

    
392
	// ---------------------Init APPSYS---------------------------------
393
	if (dbo.BeginSelectRcdSet(SQL_APPSYS) != SEDB_SUCCESS)
394
		return FALSE;
395

    
396
	retcount = dbo.GetRcdCount();
397
	if(retcount >0)
398
	{
399
		m_appSysType.SetSize(retcount);
400

    
401
		m_appSysMap.InitHashTable((UINT)(retcount*1.2));
402

    
403
		for (i = 0; i < retcount; i++)
404
		{
405
			m_appSysType[i].sAppSys = dbo.GetByteVal(i, 0);
406
			strcpy(m_appSysType[i].szDesc, dbo.GetStringVal(i, 1));
407

    
408
			m_appSysMap[m_appSysType[i].sAppSys] = i;
409
		}
410
	}
411
	dbo.EndSelectRcdSet();
412

    
413
	// ---------------------Init Field-------------------------------
414
// 	if (dbo.BeginSelectRcdSet(SQL_ALMH_FLD) != SEDB_SUCCESS)
415
// 		return FALSE;
416
// 
417
// 	CReadConf cfg;
418
// 	COLTYPE ct;
419
// 	char szWidth[MAX_PATH];
420
// 	char width[10];
421
// 	short datalen;
422
// 
423
// 	m_nCols = dbo.GetRcdCount();
424
//     if(m_nCols >0)
425
// 	{
426
// 		m_colType.SetSize(m_nCols);
427
// 		for (i = 0; i < m_nCols; i++)
428
// 		{
429
// 			strcpy(ct.szName, dbo.GetStringVal(i, 0));
430
// 			datalen = dbo.GetShortVal(i, 1);
431
// 
432
// 			sprintf(szWidth, "%s????", ct.szName);
433
// 			sprintf(width, "%d", datalen > 0 ? min(datalen, 64) * 8 : 64);
434
// 			ct.lWidth = cfg.ReadLong("History", szWidth, pApp->m_szCfgPath, width);
435
// 			ct.bSet = cfg.ReadLong("History", ct.szName, pApp->m_szCfgPath, "1") != 0;
436
// 			m_colType[i] = ct;
437
// 		}
438
// 	}
439
// 	dbo.EndSelectRcdSet();
440

    
441
	return TRUE;
442
}
443

    
444
void CToolView::InitCombo()
445
{
446
    int i;
447
    CImageList imgList;
448
	imgList.Create(IDB_TREE_ICONS, 18, 1, RGB(0xFF, 0xFF, 0xFF));
449
	//---------------------Init Group---------------------------------wyf 20181008
450
//	m_ctrlGroup.AddString("????");
451
	m_ctrlGroup.InsertCaption(3);
452
	for (i = 0; i < m_group.GetSize(); i++)
453
	{
454
		m_ctrlGroup.AddString(m_group[i].szDesc, i, ROOT_LEVEL + 1);
455
	}
456
   // m_ctrlGroup.SetCurSel(0);
457
	m_ctrlGroup.CheckAll(TRUE);
458
	m_ctrlGroup.SetImageList(&imgList);
459
	
460
	// -------------------------Init Priority------------------------
461
    m_ctrlPrio.InsertCaption(1);
462

    
463
	for (i = 0; i < m_priType.GetSize(); i++)
464
	{
465
	    m_ctrlPrio.AddString(m_priType[i].desc,i,ROOT_LEVEL + 1);
466
	}
467
	m_ctrlPrio.CheckAll(TRUE);
468
    m_ctrlPrio.SetImageList( &imgList );
469
	
470
	// --------------------------Init EType--------------------------
471
    m_ctrlType.InsertCaption(2);
472

    
473
	for (i = 0; i < m_evtType.GetSize(); i++)
474
	{
475
		m_ctrlType.AddString(m_evtType[i].szDesc,i,ROOT_LEVEL + 1);
476
	}
477
    m_ctrlType.CheckAll(TRUE);
478
    m_ctrlType.SetImageList( &imgList );
479

    
480
	// --------------------------Init user---------------------------
481
	m_ctrlUser.ResetContent();
482
	m_ctrlUser.AddString("????");
483
	for (i = 0; i < m_userStr.GetSize(); i++)
484
	{
485
		m_ctrlUser.AddString(m_userStr[i]);
486
	}
487
	m_ctrlUser.SetCurSel(0);
488

    
489
	// --------------------Init DevType------------------------------
490
//	m_ctrlDev.AddString(TEXT("????"));
491
	m_ctrlDev.InsertCaption(5);
492
	for (i = 0; i < m_devType.GetSize(); i++)
493
	{
494
		m_ctrlDev.AddString(m_devType[i].szDesc, i, ROOT_LEVEL + 1);
495
	}
496
	m_ctrlDev.CheckAll(TRUE);
497
	m_ctrlDev.SetImageList(&imgList);
498
//	m_ctrlDev.SetCurSel(0);
499

    
500
	//---------------------Init Aoj---------------------------------
501
	m_ctrlAoj.AddString("????");
502
	for (i = 0; i < m_aojType.GetSize(); i++)
503
	{
504
		m_ctrlAoj.AddString(m_aojType[i].szDesc);
505
	}
506
	m_ctrlAoj.SetCurSel(0);
507

    
508
	//---------------------Init AppSys ϵͳ---------------------------------
509
	m_ctrlAppSys.InsertCaption(4);
510
	for (i = 0; i < m_appSysType.GetSize(); i++)
511
	{
512
		m_ctrlAppSys.AddString(m_appSysType[i].szDesc, i, ROOT_LEVEL + 1);
513
	}
514
	m_ctrlAppSys.CheckAll(TRUE);
515
    m_ctrlAppSys.SetImageList(&imgList);	
516
}
517

    
518
void CToolView::OnRadio1() 
519
{
520
	// TODO: Add your control notification handler code here
521
	GetDlgItem(IDC_STATION)->EnableWindow(FALSE);
522
	GetDlgItem(IDC_COMBOUSR)->EnableWindow(TRUE);
523
    m_nSRadio =TRUE;
524
}
525

    
526
void CToolView::OnRadio2() 
527
{
528
	// TODO: Add your control notification handler code here
529
    GetDlgItem(IDC_COMBOUSR)->EnableWindow(FALSE);
530
	GetDlgItem(IDC_STATION)->EnableWindow(TRUE);
531
	m_nSRadio =FALSE;
532
}
533

    
534
void CToolView::OnStation() 
535
{
536
	// TODO: Add your control notification handler code here
537
	CON con;
538
	if (((CIn_hevtApp *)AfxGetApp())->m_Sel.GetConValue(con))
539
	{
540
		if(con.sDevType == 0)
541
		{
542
			m_bStation = false;
543
			GetDlgItem(IDC_STATION)->SetWindowText(con.szDesc);
544
			return;
545
		}
546
		m_con = con;
547
		m_bStation = true;
548
		GetDlgItem(IDC_STATION)->SetWindowText(con.szDesc);
549
	}
550
}
551

    
552
BOOL CToolView::GetSqlText(bool bCount, int nPageIdx)
553
{
554
    memset(m_szSql,0,sizeof(m_szSql));
555
    CString strSQL =_T("");
556
	CTime stm(m_startTime.GetYear(), m_startTime.GetMonth(), m_startTime.GetDay(),
557
		m_startHour.GetHour(), m_startHour.GetMinute(), m_startHour.GetSecond());//wyf 20181102 add min sec
558

    
559
	CTime etm(m_endTime.GetYear(), m_endTime.GetMonth(), m_endTime.GetDay(),
560
		m_endHour.GetHour(), m_endHour.GetMinute(), m_endHour.GetSecond());//wyf 20181102 add min sec
561

    
562
	// ʱ??????
563
	CString strTime;
564
	if (m_chkTime)
565
	{
566
		if (stm > etm)
567
		{
568
			memset(m_szSql,0,sizeof(m_szSql));
569
			return TRUE;
570
		}
571
		else
572
		{
573
			strTime.Format("F3001_DATE between %d and %d", stm.GetTime(), etm.GetTime());
574
		}
575
	}	
576

    
577
	// ????????????
578
	char m_szType[1536];
579
	memset(m_szType,0,sizeof(m_szType));
580
	CString strType=_T("");
581
	CString str =m_ctrlType.GetCheckedTexts();
582
	if ( str.Find("????")<0 && m_chkEvtType)
583
	{
584
		CString s;
585
		for (int i = 0; i < m_ctrlType.GetCount()-1; i++)
586
		{
587
			if (m_ctrlType.GetCheck(i))
588
			{
589
				s = m_evtType[i].szName;
590
				if (strlen(m_szType)==0)
591
				{
592
					strType = "(F3001_ALMCLASS = '" + s + "'";
593
					strcpy(m_szType,strType);
594
				}
595
				else
596
				{
597
					strType = " or F3001_ALMCLASS = '" + s + "'";
598
					strcat(m_szType,strType);
599
				}
600
			}
601
		}
602

    
603
		if (strlen(m_szType)!=0)
604
		{
605
			strType = ")";
606
			strcat(m_szType,strType);
607
		}
608
	}
609

    
610
	// ???ȼ?????
611
	CString strPrio;
612
	str =m_ctrlPrio.GetCheckedTexts();
613
	if (str.Find("????")<0 && m_chkPrior)
614
	{
615
		CString s;
616
		for (int i = 0; i < m_ctrlPrio.GetCount()-1; i++)
617
		{
618
			if (m_ctrlPrio.GetCheck(i))
619
			{
620
				s.Format("%d", m_priType[i].pri);
621
				if (strPrio.IsEmpty())
622
				{
623
					strPrio = "(F3001_ALMPRIO = " + s;
624
				}
625
				else
626
				{
627
					strPrio += " or F3001_ALMPRIO = " + s;
628
				}
629
			}
630
		}
631

    
632
		if (!strPrio.IsEmpty())
633
		{
634
			strPrio += ")";
635
		}
636
	}
637

    
638
	CString strGroup;
639
	str = m_ctrlGroup.GetCheckedTexts();
640
	if(str.Find("????") < 0 && m_chkGroup)
641
	{
642
		CString s;
643
		int tmpNum = m_ctrlGroup.GetCount();
644
		for(int i = 0; i < m_ctrlGroup.GetCount()-1; i++)
645
		{
646
			if(m_ctrlGroup.GetCheck(i))
647
			{
648
				s.Format("%s", m_group[i].szName);
649
				if (strGroup.IsEmpty())
650
				{
651
					strGroup = "(F3001_GROUPNAME = '"  + s + "'"; 
652
				}
653
				else
654
				{				
655
					strGroup += " or F3001_GROUPNAME = '"  + s + "'";
656
				}
657
			}
658
		}
659
		if (!strGroup.IsEmpty())
660
		{
661
			strGroup += ")";
662
		}
663
	}
664

    
665
	// Ȩ??????????
666
	CString strAoj;
667
	if (m_ctrlAoj.GetCurSel())
668
	{
669
		strAoj.Format("F3001_AOJ=%d",m_aojType[m_ctrlAoj.GetCurSel() - 1].sAoj);
670
	}
671

    
672
	// Ӧ????ϵͳ????
673
	CString strAppSys;
674
	str = m_ctrlAppSys.GetCheckedTexts();
675
	
676
	if(str.Find("????") < 0 && m_chkSys)
677
	{
678
		CString s;
679
		int tmpNum = m_ctrlAppSys.GetCount();
680
		for (int i = 0; i< m_ctrlAppSys.GetCount()-1; i++)
681
		{
682
			if (m_ctrlAppSys.GetCheck(i))
683
			{
684
				s.Format("%d", m_appSysType[i].sAppSys);
685
				if(strAppSys.IsEmpty())
686
				{
687
					strAppSys = "(F3001_APPSYSID = " + s;
688
				}
689
				else
690
				{
691
					strAppSys += " or F3001_APPSYSID = " + s;
692
				}
693
			}
694
		}
695
		if (!strAppSys.IsEmpty())
696
		{
697
			strAppSys += ")";
698
		}
699
	}
700
// 	if (m_ctrlAppSys.GetCurSel() && m_chkSys)
701
// 	{
702
// 		strAppSys.Format("F3001_APPSYSID = %d", m_appSysType[m_ctrlAppSys.GetCurSel() - 1].sAppSys);
703
// 	}
704

    
705
	// ?豸????????
706
	CString strDev;
707
	str = m_ctrlDev.GetCheckedTexts();
708

    
709
	if(str.Find("????")<0 && m_chkDevType)
710
	{
711
		CString s;
712
		for(int i = 0; i< m_ctrlDev.GetCount()-1; i++)
713
		{
714
			if(m_ctrlDev.GetCheck(i))
715
			{
716
				s.Format("%d", m_devType[i].sType);
717
				if(strDev.IsEmpty())
718
				{
719
					strDev = "(F3001_DEVTYPE = " + s;
720
				}
721
				else
722
				{
723
					strDev += " or F3001_DEVTYPE = " + s;
724
				}
725
			}
726
		}
727
		if(!strDev.IsEmpty())
728
		{
729
			strDev += ")";
730
		}
731
	}
732
// 	if (m_ctrlDev.GetCurSel() && m_chkDevType)
733
// 	{
734
// 		strDev.Format("F3001_DEVTYPE = %d", m_devType[m_ctrlDev.GetCurSel() - 1].sType);
735
// 	}
736

    
737
	// ???????û???????
738
	CString /*strGroup,*/strUser;
739
/*	if (m_nSRadio == 1)
740
	{
741
		// ??վ
742
		if(m_bStation)
743
			strGroup.Format("F3001_GROUPNAME = '%s'", m_con.szCode);
744
	}
745
	else
746
	{
747
		// ?û?
748
		int i=m_ctrlUser.GetCurSel();
749
		if (i>0)
750
			strGroup.Format("F3001_USERATTR1 = '%s'", m_userDesStr[m_ctrlUser.GetCurSel()-1]);
751
	}
752
*/
753
	//wyf 20181102 ????
754
// 	if (m_ctrlGroup.GetCurSel() && m_chkGroup)
755
// 	{
756
// 		strGroup.Format("F3001_GROUPNAME = '%s'", m_group[m_ctrlGroup.GetCurSel() - 1].szName);
757
// 	}//wyf 20181102
758
	if(0<m_ctrlUser.GetCurSel()){
759
		strUser.Format("F3001_USERATTR1 = '%s'", m_userDesStr[m_ctrlUser.GetCurSel()-1]);
760
		if(0==strGroup.GetLength())
761
			strGroup=strGroup + strUser;
762
		else
763
			strGroup=strGroup + " AND " + strUser;
764
	}
765
	/*if(bCount)
766
	{
767
		strSQL.Format("select %s from SEDATUM.TB3001_ALMH t where %s",
768
			bCount ? "count(*)" : "*", strTime);
769
	}
770
	else
771
	{
772
		strSQL.Format("select * from(select A.*, rownum RN from(select %s from SEDATUM.TB3001_ALMH t where %s",
773
			bCount ? "count(*)" : "*", strTime);
774
	}*/
775
	if(bCount)
776
	{
777
		strSQL.Format("select %s from SEDATUM.TB3001_ALMH t",
778
			bCount ? "count(*)" : "*");
779
	}
780
	else
781
	{
782
		strSQL.Format("select * from(select A.*, rownum RN from(select %s from SEDATUM.TB3001_ALMH t",
783
			bCount ? "count(*)" : "*");
784
	}
785
	int hasWhere = 0;	//sql????where??־
786
	CString strLimt;
787
	strLimt.Format("rownum <= %d", m_lLimitCount);
788
    sprintf(m_szSql,"%s",strSQL);
789
	int ulength = strSQL.GetLength()+strTime.GetLength()+strlen(m_szType) + strPrio.GetLength()+strAoj.GetLength()+strAppSys.GetLength()+strDev.GetLength()+
790
		strGroup.GetLength() + strLimt.GetLength();
791
	if ((ulength > SQL_LimitLength) && (nPageIdx == 0))
792
		return FALSE;
793

    
794
	if (m_chkTime)
795
	{
796
		strcat(m_szSql, " where ");
797
		strcat(m_szSql, strTime);
798
		hasWhere = 1;
799
	}
800
	if (strlen(m_szType) !=0)
801
	{
802
		if (hasWhere)
803
		{
804
			strcat(m_szSql, " and ");
805
			strcat(m_szSql, m_szType);
806
		}
807
		else
808
		{
809
			strcat(m_szSql, " where ");
810
			strcat(m_szSql, m_szType);
811
			hasWhere = 1;
812
		}
813
	}
814

    
815
	if (!strPrio.IsEmpty())
816
	{
817
		if (hasWhere)
818
		{
819
			strcat(m_szSql, " and ");
820
			strcat(m_szSql, strPrio);
821
		}
822
		else
823
		{
824
			strcat(m_szSql, " where ");
825
			strcat(m_szSql, strPrio);
826
			hasWhere = 1;
827
		}
828
	}
829

    
830
	if (!strAoj.IsEmpty())
831
	{
832
		if (hasWhere)
833
		{
834
			strcat(m_szSql, " and ");
835
			strcat(m_szSql, strAoj);
836
		}
837
		else
838
		{
839
			strcat(m_szSql, " where ");
840
			strcat(m_szSql, strAoj);
841
			hasWhere = 1;
842
		}
843
	}
844
	
845
	if (!strAppSys.IsEmpty())
846
	{
847
		if (hasWhere)
848
		{
849
			strcat(m_szSql, " and ");
850
			strcat(m_szSql, strAppSys);
851
		}
852
		else
853
		{
854
			strcat(m_szSql, " where ");
855
			strcat(m_szSql, strAppSys);
856
			hasWhere = 1;
857
		}
858
	}
859

    
860
	if (!strDev.IsEmpty())
861
	{
862
		if (hasWhere)
863
		{
864
			strcat(m_szSql, " and ");
865
			strcat(m_szSql, strDev);
866
		}
867
		else
868
		{
869
			strcat(m_szSql, " where ");
870
			strcat(m_szSql, strDev);
871
			hasWhere = 1;
872
		}
873
	}
874

    
875
	if (!strGroup.IsEmpty())
876
	{
877
		if (hasWhere)
878
		{
879
			strcat(m_szSql, " and ");
880
			strcat(m_szSql, strGroup);
881
		}
882
		else
883
		{
884
			strcat(m_szSql, " where ");
885
			strcat(m_szSql, strGroup);
886
			hasWhere = 1;
887
		}
888
	}
889
	
890
	if (hasWhere)
891
	{
892
		strcat(m_szSql, " and ");
893
		strcat(m_szSql, strLimt);
894
	}
895
	else
896
	{
897
		strcat(m_szSql, " where ");
898
		strcat(m_szSql, strLimt);
899
		hasWhere = 1;
900
	}
901
	if (nPageIdx == 0)
902
	{
903
		memset(m_filterSql, 0, sizeof(m_filterSql));
904
		strcpy(m_filterSql, m_szSql);
905
	}
906
	if(!bCount)
907
	{
908
		strcpy(m_szSql, m_filterSql);
909
		strLimt.Format(" order by F3001_Date %s, F3001_Microsec %s ", m_sortOrder ? "asc" : "desc", m_sortOrder ? "asc" : "desc");
910
		strcat(m_szSql, strLimt);
911
		char szbuf[20];
912
		memset(szbuf, 0, sizeof(szbuf));
913
		int Max_RN = (nPageIdx + 1) * m_lCount;
914
		itoa(Max_RN, szbuf, 10);
915
		strcat(m_szSql, ") A where rownum <= ");
916
		strcat(m_szSql, szbuf);
917
		strcat(m_szSql, ") where RN > ");
918
		int	Min_RN = nPageIdx * m_lCount;
919
		itoa(Min_RN, szbuf, 10);
920
		strcat(m_szSql, szbuf);
921
	}
922
	return TRUE;
923
}
924

    
925
void CToolView::OnQuery() 
926
{
927
	// TODO: Add your control notification handler code here
928
	if(m_bBusy)
929
	{
930
		return;
931
	}
932
	nPageIdx = 0;
933
	nLastPage = 1;
934
	GetDlgItem(IDC_QUERY)->EnableWindow(FALSE);
935
	m_bBusy = true;
936
// 	BeginWaitCursor();
937
	IsAlreadyQueryed = FALSE;
938
 	UpdateData();
939
	m_queryThread = AfxBeginThread(RunQueryPro, this, THREAD_PRIORITY_NORMAL, 0, 0, NULL);
940
}
941

    
942
UINT CToolView::RunQueryPro(LPVOID lParam)
943
{
944
	CToolView *pTool = (CToolView*)lParam;
945
	if (pTool == NULL)
946
	{
947
		pTool->m_queryThread = NULL;
948
		pTool->m_bBusy = false;
949
		return 0;
950
	}
951
	CEhhevtView* pView = pTool->m_pMain->GetView();
952
	pTool->m_stopQueryThreadFlag = FALSE;
953
	pView->m_pGridCtrl->SetTextBkColor(g_pApp->m_GridBkColor);
954
	//??ѯ??¼????
955
	if (!pTool->GetSqlText(true) || strlen(pTool->m_szSql) > SQL_LimitLength)	//sql??䳬??4095?ֽڲ???ѯ
956
	{
957
		//pTool->EndWaitCursor();
958
		pTool->GetDlgItem(IDC_QUERY)->EnableWindow(TRUE);
959
		pTool->m_queryThread = NULL;
960
		pTool->m_bBusy = false;
961
		return 0;
962
	}
963
	if (strlen(pTool->m_szSql) == 0)
964
	{
965
		AfxMessageBox("????ȷѡ???ѯʱ??!");
966
		//pTool->EndWaitCursor();
967
		pTool->GetDlgItem(IDC_QUERY)->EnableWindow(TRUE);
968
		pTool->m_queryThread = NULL;
969
		pTool->m_bBusy = false;
970
		return 0;
971
	}
972

    
973
	if (pTool->m_dbOption.BeginSelectRcdSet(pTool->m_szSql) != SEDB_SUCCESS)
974
	{
975
		pTool->GetDlgItem(IDC_QUERY)->EnableWindow(TRUE);
976
		//pTool->EndWaitCursor();
977
		pTool->m_queryThread = NULL;
978
		pTool->m_bBusy = false;
979
		return 0;
980
	}
981
	if (pTool->m_stopQueryThreadFlag)
982
	{
983
		pTool->m_dbOption.EndSelectRcdSet();
984
		pTool->m_queryThread = NULL;
985
		pTool->m_bBusy = false;
986
		return 0;
987
	}
988
	pTool->lCount = *(long*)pTool->m_dbOption.GetColVal(0, 0);
989
//	pTool->m_findCount = pTool->lCount;
990
	if (pTool->lCount % pTool->m_lCount)
991
	{
992
		pTool->nLastPage = pTool->lCount / pTool->m_lCount;
993
	}
994
	else
995
	{
996
		pTool->nLastPage = pTool->lCount / pTool->m_lCount - 1;
997
	}
998
	pTool->m_dbOption.EndSelectRcdSet();
999

    
1000

    
1001
	//??ѯ??¼
1002
	if (!pTool->GetSqlText() || strlen(pTool->m_szSql) > SQL_LimitLength)
1003
	{
1004
		//pTool->EndWaitCursor();
1005
		pTool->GetDlgItem(IDC_QUERY)->EnableWindow(TRUE);
1006
		pTool->m_queryThread = NULL;
1007
		pTool->m_bBusy = false;
1008
		return 0;
1009
	}
1010
	if (strlen(pTool->m_szSql) == 0)
1011
	{
1012
		AfxMessageBox("????ȷѡ???ѯʱ??!");
1013
		//pTool->EndWaitCursor();
1014
		pTool->GetDlgItem(IDC_QUERY)->EnableWindow(TRUE);
1015
		pTool->IsAlreadyQueryed = TRUE;
1016
		pTool->m_queryThread = NULL;
1017
		pTool->m_bBusy = false;
1018
		return 0;
1019
	}
1020
	if (pTool->m_stopQueryThreadFlag)
1021
	{
1022
		//pTool->GetDlgItem(IDC_QUERY)->EnableWindow(TRUE);
1023
		pTool->m_queryThread = NULL;
1024
		pTool->m_bBusy = false;
1025
		return 0;
1026
	}
1027
	if (pTool->m_dbOption.BeginSelectRcdSet(pTool->m_szSql) != SEDB_SUCCESS)
1028
	{
1029
		pTool->ResetGridContext();
1030
		//pTool->EndWaitCursor();
1031
		pTool->GetDlgItem(IDC_QUERY)->EnableWindow(TRUE);
1032
		pTool->IsAlreadyQueryed = TRUE;
1033
		pTool->m_queryThread = NULL;
1034
		pTool->m_bBusy = false;
1035
		return 0;
1036
	}
1037
	if (pTool->m_stopQueryThreadFlag)
1038
	{
1039
		pTool->m_queryThread = NULL;
1040
		//pTool->GetDlgItem(IDC_QUERY)->EnableWindow(TRUE);
1041
		pTool->m_dbOption.EndSelectRcdSet();
1042
		pTool->m_bBusy = false;
1043
		return 0;
1044
	}
1045
	pTool->m_nRows = pTool->m_dbOption.GetRcdCount();
1046

    
1047
	pTool->m_pMain->SetcolNum(pTool->lCount);
1048
	pTool->m_pMain->SetPageNum(pTool->nPageIdx + 1, pTool->nLastPage + 1);
1049
	pView->m_pGridCtrl->LockWindowUpdate();
1050
	pView->m_pGridCtrl->m_bLockWindow = TRUE;	//??ֹ????
1051
	pView->m_pGridCtrl->DeleteAllItems();
1052
	//pView->m_nRows = pTool->m_nRows;
1053
	pView->m_nRows = pTool->m_lCount;
1054
	pTool->m_nCols = pView->m_nCols;
1055
	pView->InitGridHead();
1056
	int add = 0;
1057
	if (pView->m_almOrderNumFlag)
1058
		add = 1;
1059
	for (int row = 0; row < pTool->m_nRows; row++)
1060
	{
1061
		if (pTool->m_stopQueryThreadFlag)
1062
		{
1063
			pTool->m_queryThread = NULL;
1064
			//pTool->GetDlgItem(IDC_QUERY)->EnableWindow(TRUE);
1065
			pView->m_pGridCtrl->m_bLockWindow = FALSE;
1066
			pTool->m_dbOption.EndSelectRcdSet();
1067
			pTool->m_bBusy = false;
1068
			return 0;
1069
		}
1070
		int index = pTool->GetPriorityNo(pTool->m_dbOption.GetByteVal(row, 5));
1071
		GV_ITEM Item;
1072
		Item.mask = GVIF_TEXT;
1073
		Item.row = row + 1;
1074
		Item.col = 0;
1075
		CString strText;
1076
		strText.Format("%d", row + 1);
1077
		Item.strText = strText;
1078
		pView->m_pGridCtrl->SetItem(&Item);
1079
		for (int col = 0; col < pTool->m_nCols; col++)
1080
		{
1081
			if (pTool->m_stopQueryThreadFlag)
1082
			{
1083
				pTool->m_queryThread = NULL;
1084
				//pTool->GetDlgItem(IDC_QUERY)->EnableWindow(TRUE);
1085
				pView->m_pGridCtrl->m_bLockWindow = FALSE;
1086
				pTool->m_dbOption.EndSelectRcdSet();
1087
				pTool->m_bBusy = false;
1088
				return 0;
1089
			}
1090
			GV_ITEM Item;
1091
			Item.mask = GVIF_TEXT;
1092
			Item.row = row + 1;
1093
			Item.col = col + add;
1094
			long lData;
1095
			Item.strText = pTool->GetGridText(row, col, lData);
1096
			// primary key, save number data to lParam
1097
			if (col == 1 || col == 2 || col == 3 || col == 5)
1098
			{
1099
				Item.mask |= GVIF_PARAM;
1100
				Item.lParam = (LPARAM)lData;
1101
			}
1102
			if (!pTool->m_bAlarmClr)
1103
			{
1104
 				Item.mask |= GVIF_BKCLR;
1105
 				Item.mask |= GVIF_FGCLR;
1106
 				Item.crFgClr = RGB(255, 255, 255);
1107
 				Item.crBkClr = g_pApp->m_GridBkColor;
1108
 			}
1109
 			else
1110
			{
1111
				if (col >= 0 && index >= 0)
1112
				{
1113
					Item.mask |= GVIF_BKCLR;
1114
					Item.mask |= GVIF_FGCLR;//WYF 20180719
1115
					//				Item.crBkClr = m_priType[index].color;
1116
					Item.crFgClr = pTool->m_priType[index].color;//WYF 20180719
1117
					Item.crBkClr = g_pApp->m_GridBkColor;//WYF 20180719
1118
				}
1119
				else if (index < 0)
1120
				{
1121
					Item.mask |= GVIF_BKCLR;
1122
					Item.mask |= GVIF_FGCLR;
1123
					Item.crFgClr = RGB(255, 255, 255);
1124
					Item.crBkClr = RGB(7, 54, 80);
1125
				}
1126
			}
1127
			pView->m_pGridCtrl->SetItem(&Item);
1128
		}
1129
	}
1130
	pTool->m_dbOption.EndSelectRcdSet();
1131
	pView->m_pGridCtrl->m_bLockWindow = FALSE;
1132
	pView->m_pGridCtrl->UnlockWindowUpdate();
1133
	//    pView->m_pGridCtrl->AutoSize();//WYF 20180719
1134
	//pTool->EndWaitCursor();
1135
	if (!pTool->m_stopQueryThreadFlag)
1136
		pTool->GetDlgItem(IDC_QUERY)->EnableWindow(TRUE);
1137
	pTool->IsAlreadyQueryed = TRUE;
1138
	pTool->m_queryThread = NULL;
1139
	pTool->m_bBusy = false;
1140
	return 0;
1141
}
1142

    
1143
BOOL CToolView::StopRunQueryPro()
1144
{
1145
	if (m_queryThread != NULL)
1146
	{
1147
		while (m_queryThread != NULL)
1148
		{
1149
			m_stopQueryThreadFlag = TRUE;
1150
		}
1151
	//	kprintf(LOG_ALARM, 1, LOG_WARNING, "in_hevt queryThread is stoped! ");
1152
	}
1153
	if (m_queryNextThread != NULL)
1154
	{
1155
		while (m_queryNextThread != NULL)
1156
		{
1157
			m_stopQueryThreadFlag = TRUE;
1158
		}
1159
	}
1160
	return TRUE;
1161
}
1162

    
1163
void CToolView::Page(int nFlags, int nSkip)
1164
{
1165
	if (m_bBusy)
1166
	{
1167
		return;
1168
	}
1169
	m_nFlags = nFlags;
1170
	m_nSkip = nSkip;
1171
	m_bBusy = true;
1172
	m_queryNextThread = AfxBeginThread(RunPreNextQueryPro, this, THREAD_PRIORITY_NORMAL, 0, 0, NULL);
1173
}
1174

    
1175
UINT CToolView::RunPreNextQueryPro(LPVOID lParam)
1176
{
1177
	CToolView *pTool = (CToolView*)lParam;
1178
	if (pTool == NULL)
1179
	{
1180
		pTool->m_queryNextThread = NULL;
1181
		pTool->m_bBusy = false;
1182
		return 0;
1183
	}
1184
	pTool->m_bBusy = true;
1185
	pTool->m_stopQueryThreadFlag = FALSE;
1186
	CEhhevtView* pView = pTool->m_pMain->GetView();
1187
	pView->m_pGridCtrl->SetTextBkColor(g_pApp->m_GridBkColor);
1188
	const int PAGE[] = { 0, pTool->nPageIdx - 1, pTool->nPageIdx + 1, pTool->nLastPage, pTool->m_nSkip - 1 };
1189
	if (!pTool->GetSqlText(false, PAGE[pTool->m_nFlags]) || strlen(pTool->m_szSql) > SQL_LimitLength)
1190
	{
1191
		pTool->m_bBusy = false;
1192
		pTool->m_queryNextThread = NULL;
1193
		return 0;
1194
	}
1195
	pTool->nPageIdx = PAGE[pTool->m_nFlags];
1196
	
1197
	if (pTool->m_dbOption.BeginSelectRcdSet(pTool->m_szSql) != SEDB_SUCCESS)
1198
	{
1199
		pTool->m_bBusy = false;
1200
		pTool->m_queryNextThread = NULL;
1201
		return 0;
1202
	}
1203

    
1204
	int m_nRows = pTool->m_dbOption.GetRcdCount();
1205
	//	pMain->SetcolNum(m_nRows);
1206
	
1207
	pView->m_pGridCtrl->LockWindowUpdate();
1208
	pView->m_pGridCtrl->m_bLockWindow = TRUE;
1209
	//pView->m_pGridCtrl->DeleteAllItems();
1210
	pView->m_pGridCtrl->DeleteAllCellContent();
1211
	//pView->m_nRows = m_nRows;
1212
	pView->m_nRows = pTool->m_lCount;
1213
	//m_nCols = pView->m_nCols;
1214
	int nColWid = pView->m_pGridCtrl->GetColumnWidth(0);
1215
	pView->InitGridHead();
1216
	pView->m_pGridCtrl->SetColumnWidth(0,nColWid);
1217
	int add = 0;
1218
	if (pView->m_almOrderNumFlag)
1219
		add = 1;
1220
	for (int row = 0; row < m_nRows; row++)
1221
	{
1222
		if (pTool->m_stopQueryThreadFlag)
1223
		{
1224
			pTool->m_queryNextThread = NULL;
1225
			pView->m_pGridCtrl->m_bLockWindow = FALSE;
1226
			pTool->m_dbOption.EndSelectRcdSet();
1227
			pTool->m_bBusy = false;
1228
			return 0;
1229
		}
1230
		int index = pTool->GetPriorityNo(pTool->m_dbOption.GetByteVal(row, 5));
1231
		GV_ITEM Item;
1232
		Item.mask = GVIF_TEXT;
1233
		Item.row = row + 1;
1234
		Item.col = 0;
1235
		CString strText;
1236
		strText.Format("%d", row + 1);
1237
		Item.strText = strText;
1238
		pView->m_pGridCtrl->SetItem(&Item);
1239
		for (int col = 0; col < pTool->m_nCols; col++)
1240
		{
1241
			if (pTool->m_stopQueryThreadFlag)
1242
			{
1243
				pTool->m_queryNextThread = NULL;
1244
				pView->m_pGridCtrl->m_bLockWindow = FALSE;
1245
				pTool->m_dbOption.EndSelectRcdSet();
1246
				pTool->m_bBusy = false;
1247
				return 0;
1248
			}
1249
			GV_ITEM Item;
1250
			Item.mask = GVIF_TEXT;
1251
			Item.row = row + 1;
1252
			Item.col = col + add;
1253
			long lData;
1254
			Item.strText = pTool->GetGridText(row, col, lData);
1255
			// primary key, save number data to lParam
1256
			if (col == 1 || col == 2 || col == 3 || col == 5)
1257
			{
1258
				Item.mask |= GVIF_PARAM;
1259
				Item.lParam = (LPARAM)lData;
1260
			}
1261
			if (!pTool->m_bAlarmClr)
1262
			{
1263
				Item.mask |= GVIF_BKCLR;
1264
				Item.mask |= GVIF_FGCLR;
1265
				Item.crFgClr = RGB(255, 255, 255);
1266
				Item.crBkClr = g_pApp->m_GridBkColor;
1267
			}
1268
			else
1269
			{
1270
				if (col >= 0 && index >= 0)
1271
				{
1272
					Item.mask |= GVIF_BKCLR;
1273
					Item.mask |= GVIF_FGCLR;//WYF 20180719
1274
					//				Item.crBkClr = m_priType[index].color;
1275
					Item.crFgClr = pTool->m_priType[index].color;//WYF 20180719
1276
					Item.crBkClr = g_pApp->m_GridBkColor;//WYF 20180719
1277
				}
1278
				else if (index < 0)
1279
				{
1280
					Item.mask |= GVIF_BKCLR;
1281
					Item.mask |= GVIF_FGCLR;
1282
					Item.crFgClr = RGB(255, 255, 255);
1283
					Item.crBkClr = RGB(7, 54, 80);
1284
				}
1285
			}
1286
			pView->m_pGridCtrl->SetItem(&Item);
1287
		}
1288
	}
1289
	pTool->m_pMain->SetPageNum(pTool->nPageIdx + 1, pTool->nLastPage + 1);
1290
	pTool->m_dbOption.EndSelectRcdSet();
1291
	pView->m_pGridCtrl->m_bLockWindow = FALSE;
1292
	pView->m_pGridCtrl->UnlockWindowUpdate();
1293
	pView->m_pGridCtrl->Refresh();
1294
	pTool->m_bBusy = false;
1295
	pTool->m_queryNextThread = NULL;
1296
	return 0;
1297
}
1298

    
1299
void CToolView::ResetGridContext()
1300
{}
1301

    
1302
int CToolView::GetPriorityNo(int pri)
1303
{
1304
    for (int i = 0; i < m_priType.GetSize(); i++)
1305
	{
1306
		if (m_priType[i].pri == pri)
1307
			return i;
1308
	}
1309
	return -1;
1310
}
1311
//lDataʹ????ɾ???޸Ĺ??????ѷ???---add by sjw 2020.1.14
1312
CString CToolView::GetGridText(int row, int col, long &lData)
1313
{
1314
    CSeTime SE_T;
1315
	static SSE_CLOCK clock;
1316

    
1317
	CString strText;
1318
	CMainFrame* pFrmae = m_pMain;
1319
			
1320
	char buf[64];
1321
	memset(buf,0,sizeof(buf));
1322
	strcpy(buf,pFrmae->GetView()->m_colType[col].szName);
1323

    
1324
	if(strcmp(buf ,"???к?")==0)
1325
		{
1326
			BYTE serial = m_dbOption.GetByteVal(row, 4);
1327
			lData = serial;
1328
			strText.Format("%d", serial);
1329
		}
1330
	
1331
	
1332
	else if(strcmp(buf ,"ʱ??")==0)
1333
		{
1334
			TCriterionTime second = m_dbOption.GetIntVal(row, _T("F3001_DATE"));
1335
			short ms = m_dbOption.GetShortVal(row, _T("F3001_MICROSEC"));
1336
			lData = second;
1337
			SE_T.CovertTime(second, &clock);
1338
//			strText.Format("%04d-%02d-%02d %02d:%02d:%02d.%03d", clock.year, clock.month, clock.day, clock.hour, clock.minute, clock.second,ms);
1339
			strText.Format("%04d%s%02d%s%02d %02d:%02d:%02d.%03d", clock.year,m_sDiv, clock.month,m_sDiv, clock.day, clock.hour, clock.minute, clock.second,ms);
1340
		}
1341

    
1342

    
1343
else if(strcmp(buf ,"????")==0)
1344
		{
1345
			short ms = m_dbOption.GetShortVal(row, _T("F3001_MICROSEC"));
1346
			lData = ms;
1347
			strText.Format("%03d", ms);
1348
		}
1349

    
1350

    
1351
else if(strcmp(buf ,"?豸")==0)
1352
	{
1353
		strText = m_dbOption.GetStringVal(row, _T("F3001_DEVKEY"));
1354
	}
1355

    
1356
else if(strcmp(buf ,"??????")==0)
1357
		{
1358
			char *pszType = m_dbOption.GetStringVal(row, _T("F3001_ALMCLASS"));
1359
			short sIndex = -1;
1360
			if(pszType != NULL)
1361
			{
1362
				if (m_TypeMap.Lookup(pszType, sIndex))
1363
				strText = m_evtType[sIndex].szDesc;
1364
			}
1365
			else
1366
			{
1367
				strText = _T("");
1368
			}
1369
			lData = sIndex;
1370
		}
1371
		else if(strcmp(buf ,"???????ȼ?")==0)
1372
		{
1373
			BYTE prio = m_dbOption.GetByteVal(row, _T("F3001_ALMPRIO"));
1374
			int index = GetPriorityNo(prio);
1375
			if (index >= 0)
1376
				strText = m_priType[index].desc;
1377
			else
1378
				strText.Format("%d", prio);
1379
		}
1380
	
1381
else if(strcmp(buf ,"??ϵͳ")==0)
1382
		{
1383
			short appsysid = m_dbOption.GetShortVal(row, _T("F3001_APPSYSID"));
1384
			short sIndex;
1385
			if (m_appSysMap.Lookup(appsysid, sIndex))
1386
				strText = m_appSysType[sIndex].szDesc;
1387
		}
1388
	
1389
else if(strcmp(buf ,"Ȩ??????")==0)
1390
		{
1391
			unsigned int aoj = m_dbOption.GetIntVal(row, _T("F3001_AOJ"));
1392
			short sIndex;
1393
			if (m_aojMap.Lookup(aoj, sIndex))
1394
				strText = m_aojType[sIndex].szDesc;
1395
	
1396
		}
1397
	
1398
else if(strcmp(buf ,"?豸????")==0)
1399
		{
1400
			short devType = m_dbOption.GetShortVal(row, _T("F3001_DEVTYPE"));
1401
			short sIndex;
1402
			if (m_devMap.Lookup(devType, sIndex))
1403
				strText = m_devType[sIndex].szDesc;
1404
		}
1405

    
1406
else if(strcmp(buf ,"????")==0)
1407
		{
1408
			char szSQL[100];
1409
			sprintf(szSQL, "select F1001_GROUPDESC from SEMODEL.TB1001_GROUP "
1410
				"where F1001_GROUPCODE = '%s'", m_dbOption.GetStringVal(row, 9));
1411
			CSE_DBOption dbo;
1412
			if (dbo.BeginSelectRcdSet(szSQL) != SEDB_SUCCESS)
1413
				return _T("");
1414
			int nRetcount = m_dbOption.GetRcdCount(); 
1415
			if(nRetcount <= 0)
1416
				strText = _T("");
1417
			strText = dbo.GetStringVal(0, _T("F1001_GROUPDESC"));
1418
			dbo.EndSelectRcdSet();
1419
		}
1420

    
1421
else if(strcmp(buf ,"?û?????1")==0)
1422
		{
1423
			strText = m_dbOption.GetStringVal(row, _T("F3001_USERATTR1"));
1424
		}
1425

    
1426
else if(strcmp(buf ,"?û?????2")==0)
1427
		{
1428
			strText = m_dbOption.GetStringVal(row, _T("F3001_USERATTR2"));
1429
		}
1430

    
1431
else if(strcmp(buf ,"?û?????3")==0)
1432
		{
1433
			strText = m_dbOption.GetStringVal(row, _T("F3001_USERATTR3"));
1434
		}
1435

    
1436
else if(strcmp(buf ,"?û?????4")==0)
1437
		{
1438
			strText = m_dbOption.GetStringVal(row, _T("F3001_USERATTR4"));
1439
		}	
1440
else if(strcmp(buf ,"??????????Ϣ")==0)
1441
		{
1442
			strText = m_dbOption.GetStringVal(row, _T("F3001_TEXT"));
1443
		}
1444
else if (strcmp(buf, "?Ƿ?ȷ??") == 0)
1445
{
1446
	short stateMode = m_dbOption.GetShortVal(row, _T("F3001_STATE"));
1447
	if (stateMode&((int)BeConfirm))
1448
	{
1449
		strText = _T("??ȷ??");
1450
	}
1451
	else
1452
	{
1453
		strText = _T("δȷ??");
1454
	}
1455
}
1456
else if (strcmp(buf, "?Ƿ?ָ?") == 0)
1457
{
1458
	short stateMode = m_dbOption.GetShortVal(row, _T("F3001_STATE"));
1459
	if (stateMode & ((int)BeResume))
1460
	{
1461
		strText = _T("?ѻָ?");
1462
	}
1463
	else
1464
	{
1465
		strText = _T("δ?ָ?");
1466
	}
1467
}
1468
else if (strcmp(buf, "?ָ?ʱ????") == 0)
1469
{
1470
	short stateMode = m_dbOption.GetShortVal(row, _T("F3001_STATE"));
1471
	short ms = m_dbOption.GetShortVal(row, _T("F3001_RSTMS"));
1472
	TCriterionTime secondNum = m_dbOption.GetIntVal(row, _T("F3001_RSTTIME"));
1473
	if ((stateMode & ((int)BeResume)) && ms >= 0 && secondNum > 0)
1474
	{
1475
		SE_T.CovertTime(secondNum, &clock);
1476
//		strText.Format("%04d-%02d-%02d %02d:%02d:%02d.%03d", clock.year, clock.month, clock.day, clock.hour, clock.minute, clock.second, ms);
1477
		strText.Format("%04d-%02d-%02d %02d:%02d:%02d.%03d", clock.year,m_sDiv, clock.month,m_sDiv, clock.day, clock.hour, clock.minute, clock.second, ms);
1478
	}
1479
	else
1480
	{
1481
		strText = _T("");
1482
	}
1483
}
1484
else if (strcmp(buf, "ȷ??ʱ????") == 0)
1485
{
1486
	short stateMode = m_dbOption.GetShortVal(row, _T("F3001_STATE"));
1487
	short ms = m_dbOption.GetShortVal(row, _T("F3001_ACKMS"));
1488
	TCriterionTime secondNum = m_dbOption.GetIntVal(row, _T("F3001_ACKTIME"));
1489
	if ((stateMode & ((int)BeConfirm)) && ms >= 0 && secondNum > 0)
1490
	{
1491
		SE_T.CovertTime(secondNum, &clock);
1492
//		strText.Format("%04d-%02d-%02d %02d:%02d:%02d.%03d", clock.year, clock.month, clock.day, clock.hour, clock.minute, clock.second, ms);
1493
		strText.Format("%04d-%02d-%02d %02d:%02d:%02d.%03d", clock.year,m_sDiv, clock.month,m_sDiv, clock.day, clock.hour, clock.minute, clock.second, ms);		
1494
	}
1495
	else
1496
	{
1497
		strText = _T("");
1498
	}
1499
}
1500
else if (strcmp(buf, "ȷ??ʱ?????") == 0)
1501
{
1502
	short ms = m_dbOption.GetShortVal(row, _T("F3001_ACKMS"));
1503
	if (ms >= 0)
1504
	{
1505
		strText.Format("%03d", ms);
1506
	}
1507
	else
1508
	{
1509
		strText = _T("");
1510
	}
1511
}
1512
else if (strcmp(buf, "?ָ?ʱ?????") == 0)
1513
{
1514
	short ms = m_dbOption.GetShortVal(row, _T("F3001_RSTMS"));
1515
	if (ms >= 0)
1516
	{
1517
		strText.Format("%03d", ms);
1518
	}
1519
	else
1520
	{
1521
		strText = _T("");
1522
	}
1523
}
1524
else if (strcmp(buf, "ȷ????") == 0)
1525
{
1526
	short stateMode = m_dbOption.GetShortVal(row, _T("F3001_STATE"));
1527
	if (stateMode & ((int)BeConfirm))
1528
	{
1529
		strText = m_dbOption.GetStringVal(row, _T("F3001_ACKER"));
1530
	}
1531
	else
1532
		strText = _T("");
1533
}
1534
else
1535
{
1536
	strText = _T("");
1537
}
1538

    
1539
	
1540
	return strText;
1541
}
1542

    
1543

    
1544
void CToolView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo) 
1545
{
1546
	// TODO: Add your specialized code here and/or call the base class
1547
	CMainFrame* pMain = m_pMain;
1548
    CEhhevtView* pView =pMain->GetView();
1549
	if(pView !=NULL)
1550
	{
1551
	   if (pView->m_pGridCtrl)
1552
		   pView->m_pGridCtrl->OnBeginPrinting(pDC, pInfo);
1553
	}
1554

    
1555
}
1556

    
1557
void CToolView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo) 
1558
{
1559
	// TODO: Add your specialized code here and/or call the base class
1560
	CMainFrame* pMain = m_pMain;
1561
    CEhhevtView* pView =pMain->GetView();
1562
	if(pView !=NULL)
1563
	{
1564
	   if (pView->m_pGridCtrl)
1565
	       pView->m_pGridCtrl->OnEndPrinting(pDC, pInfo);
1566
	}
1567
}
1568

    
1569
/*BOOL CToolView::OnPreparePrinting(CPrintInfo* pInfo) 
1570
{
1571
	// TODO: call DoPreparePrinting to invoke the Print dialog box
1572
	return DoPreparePrinting(pInfo);
1573

    
1574
}*/
1575
void CToolView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
1576
{
1577
	CMainFrame* pMain = m_pMain;
1578
    CEhhevtView* pView =pMain->GetView();
1579
	if(pView !=NULL)
1580
	{
1581
	    if (pView->m_pGridCtrl)
1582
		   pView->m_pGridCtrl->OnPrint(pDC, pInfo);
1583
	}
1584
}
1585

    
1586
void CToolView::OnBtnPrint() 
1587
{
1588
	CMainFrame* pMain = m_pMain;
1589
    CEhhevtView* pView =pMain->GetView();
1590
	if(pView !=NULL)
1591
	{
1592
		pView->m_pGridCtrl->Print();
1593
	}
1594
}
1595

    
1596
void CToolView::OnChkGroup()
1597
{
1598
	UpdateData();
1599
	GetDlgItem(IDC_BUTTON_GROUP)->EnableWindow(m_chkGroup);
1600
}
1601
void CToolView::OnStaticGroup()
1602
{
1603
	m_chkGroup = !m_chkGroup;
1604
	UpdateData(FALSE);
1605
	GetDlgItem(IDC_BUTTON_GROUP)->EnableWindow(m_chkGroup);
1606
}
1607

    
1608
void CToolView::OnChkSys()
1609
{
1610
	UpdateData();
1611
	GetDlgItem(IDC_BUTTON_APPSYS)->EnableWindow(m_chkSys);
1612
}
1613

    
1614
void CToolView::OnStaticSys()
1615
{
1616
	m_chkSys = !m_chkSys;
1617
	UpdateData(FALSE);
1618
	GetDlgItem(IDC_BUTTON_APPSYS)->EnableWindow(m_chkSys);
1619
}
1620

    
1621
void CToolView::OnChkDevType()
1622
{
1623
	UpdateData();
1624
	GetDlgItem(IDC_BUTTON_DEVICE)->EnableWindow(m_chkDevType); //IDC_COMBODEV
1625
}
1626

    
1627
void CToolView::OnStaticDevType()
1628
{
1629
	m_chkDevType = !m_chkDevType;
1630
	UpdateData(FALSE);
1631
	GetDlgItem(IDC_BUTTON_DEVICE)->EnableWindow(m_chkDevType); //IDC_COMBODEV
1632
}
1633

    
1634
void CToolView::OnChkPrior()
1635
{
1636
	UpdateData();
1637
	GetDlgItem(IDC_BUTTON_SORT)->EnableWindow(m_chkPrior);
1638
}
1639

    
1640
void CToolView::OnStaticPrior()
1641
{
1642
	m_chkPrior = !m_chkPrior;
1643
	UpdateData(FALSE);
1644
	GetDlgItem(IDC_BUTTON_SORT)->EnableWindow(m_chkPrior);
1645
}
1646

    
1647
void CToolView::OnChkEvtType()
1648
{
1649
	UpdateData();
1650
	GetDlgItem(IDC_BUTTON_TYPE)->EnableWindow(m_chkEvtType);
1651
}
1652

    
1653
void CToolView::OnStaticEvtType()
1654
{
1655
	m_chkEvtType = !m_chkEvtType;
1656
	UpdateData(FALSE);
1657
	GetDlgItem(IDC_BUTTON_TYPE)->EnableWindow(m_chkEvtType);
1658
}
1659

    
1660
void CToolView::OnChkTime()
1661
{
1662
	UpdateData();
1663
	GetDlgItem(IDC_DATETIMEPICKER1)->EnableWindow(m_chkTime);
1664
	GetDlgItem(IDC_DATETIMEPICKER3)->EnableWindow(m_chkTime);
1665
	GetDlgItem(IDC_DATETIMEPICKER2)->EnableWindow(m_chkTime);
1666
	GetDlgItem(IDC_DATETIMEPICKER4)->EnableWindow(m_chkTime);
1667
}
1668

    
1669
void CToolView::OnStaticTime()
1670
{
1671
	m_chkTime = !m_chkTime;
1672
	UpdateData(FALSE);
1673
	GetDlgItem(IDC_DATETIMEPICKER1)->EnableWindow(m_chkTime);
1674
	GetDlgItem(IDC_DATETIMEPICKER3)->EnableWindow(m_chkTime);
1675
	GetDlgItem(IDC_DATETIMEPICKER2)->EnableWindow(m_chkTime);
1676
	GetDlgItem(IDC_DATETIMEPICKER4)->EnableWindow(m_chkTime);
1677
}
1678

    
1679
void CToolView::OnLButtonDblClk(UINT nFlags, CPoint point)
1680
{
1681
	return;
1682
}
1683

    
1684
void CToolView::OnLButtonDown(UINT nFlags, CPoint pt )
1685
{
1686
	CCheckComboBox::HideActiveDropDown();
1687
	return;
1688
}
1689

    
1690
void CToolView::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
1691
{
1692
	UpdateDialogControls(pTarget, FALSE);
1693
}
1694

    
1695
CSize CToolView::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
1696
{
1697
	CMiniDockFrameWnd*   pFrame   =   ((CMiniDockFrameWnd*)m_pDockBar->GetParent());   
1698
	CRect   rc;   
1699
    pFrame->GetClientRect(&rc);
1700
	int nHorzDockBarWidth = bStretch ? 32767 : rc.Width() + 4;
1701
    int nVertDockBarHeight = bStretch ? 32767 : rc.Height() + 4;
1702
	if (bHorz)
1703
	{
1704
		return CSize(345, nVertDockBarHeight);
1705
	}
1706
	else
1707
	{
1708
		return CSize(345, nVertDockBarHeight);
1709
	}
1710
}
1711

    
1712
void CToolView::OnSize(UINT nType, int cx, int cy)
1713
{
1714
	CDialogBar::OnSize(nType, cx, cy);
1715
	
1716
	//?ƶ????????ڸDZ߿?
1717
	CRect wrc;
1718
	GetWindowRect(&wrc);
1719
	wrc.OffsetRect(-wrc.left, -wrc.top);
1720
	wrc.DeflateRect(0, 2);
1721
	CRgn rgn;
1722
	BOOL bl = rgn.CreateRectRgnIndirect(&wrc);
1723
	if (bl)
1724
	{
1725
		SetWindowRgn(rgn, TRUE);
1726
	}
1727
	rgn.Detach();
1728
}
1729

    
1730
void CToolView::RefreshChildCtrl()
1731
{
1732
	GetDlgItem(IDC_DATETIMEPICKER3)->EnableWindow(!m_chkTime);
1733
	GetDlgItem(IDC_DATETIMEPICKER3)->EnableWindow(m_chkTime);
1734
	GetDlgItem(IDC_DATETIMEPICKER4)->EnableWindow(!m_chkTime);
1735
	GetDlgItem(IDC_DATETIMEPICKER4)->EnableWindow(m_chkTime);
1736
}
(5-5/11)