1
|
// EhhevtView.cpp : implementation of the CEhhevtView class
|
2
|
//
|
3
|
|
4
|
#include "stdafx.h"
|
5
|
#include "in_hevt.h"
|
6
|
#include "mainfrm.h"
|
7
|
#include "EhhevtView.h"
|
8
|
#include "sqlstmt.h"
|
9
|
#include "math.h"
|
10
|
#ifdef _DEBUG
|
11
|
#define new DEBUG_NEW
|
12
|
#undef THIS_FILE
|
13
|
static char THIS_FILE[] = __FILE__;
|
14
|
#endif
|
15
|
/////////////////////////////////////////////////////////////////////////////
|
16
|
// CEhhevtView
|
17
|
|
18
|
IMPLEMENT_DYNCREATE(CEhhevtView, CView)
|
19
|
|
20
|
BEGIN_MESSAGE_MAP(CEhhevtView, CView)
|
21
|
//{{AFX_MSG_MAP(CEhhevtView)
|
22
|
ON_WM_SIZE()
|
23
|
//}}AFX_MSG_MAP
|
24
|
// Standard printing commands
|
25
|
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
|
26
|
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
|
27
|
ON_COMMAND(IDI_ICON2/*ID_FILE_PRINT_PREVIEW*/, CView::OnFilePrintPreview)
|
28
|
ON_COMMAND(MAKELONG(10001, BN_CLICKED), OnGridSizingCol)
|
29
|
END_MESSAGE_MAP()
|
30
|
|
31
|
/////////////////////////////////////////////////////////////////////////////
|
32
|
// CEhhevtView construction/destruction
|
33
|
|
34
|
CEhhevtView::CEhhevtView()
|
35
|
{
|
36
|
// TODO: add construction code here
|
37
|
m_nCols = 0;
|
38
|
m_nRows = 0;
|
39
|
m_nFixCols = 1;
|
40
|
m_nFixRows = 1;
|
41
|
// m_pOldFrame =NULL;
|
42
|
m_pGridCtrl = NULL;
|
43
|
m_pMainFrame = NULL;
|
44
|
}
|
45
|
|
46
|
CEhhevtView::~CEhhevtView()
|
47
|
{
|
48
|
//??ͣ??ѯ?߳?,Ȼ????????
|
49
|
if (m_pMainFrame != NULL)
|
50
|
{
|
51
|
m_pMainFrame->StopToolViewQueryThread();
|
52
|
}
|
53
|
if (m_pGridCtrl)
|
54
|
{
|
55
|
delete m_pGridCtrl;
|
56
|
m_pGridCtrl = NULL;
|
57
|
}
|
58
|
}
|
59
|
|
60
|
BOOL CEhhevtView::PreCreateWindow(CREATESTRUCT& cs)
|
61
|
{
|
62
|
// TODO: Modify the Window class or styles here by modifying
|
63
|
// the CREATESTRUCT cs
|
64
|
|
65
|
return CView::PreCreateWindow(cs);
|
66
|
}
|
67
|
|
68
|
/////////////////////////////////////////////////////////////////////////////
|
69
|
// CEhhevtView drawing
|
70
|
|
71
|
void CEhhevtView::OnDraw(CDC* pDC)
|
72
|
{
|
73
|
//CEhhevtDoc* pDoc =(CEhhevtDoc*) GetDocument();
|
74
|
//ASSERT_VALID(pDoc);
|
75
|
// TODO: add draw code for native data here
|
76
|
}
|
77
|
|
78
|
/////////////////////////////////////////////////////////////////////////////
|
79
|
// CEhhevtView printing
|
80
|
|
81
|
BOOL CEhhevtView::OnPreparePrinting(CPrintInfo* pInfo)
|
82
|
{
|
83
|
// default preparation
|
84
|
|
85
|
return DoPreparePrinting(pInfo);
|
86
|
}
|
87
|
void CEhhevtView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
|
88
|
{
|
89
|
if (m_pGridCtrl)
|
90
|
m_pGridCtrl->OnPrint(pDC, pInfo);
|
91
|
}
|
92
|
void CEhhevtView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
|
93
|
{
|
94
|
// TODO: add extra initialization before printing
|
95
|
if (m_pGridCtrl)
|
96
|
m_pGridCtrl->OnBeginPrinting(pDC, pInfo);
|
97
|
}
|
98
|
|
99
|
void CEhhevtView::OnEndPrinting(CDC* pDC, CPrintInfo *pInfo)
|
100
|
{
|
101
|
// TODO: add cleanup after printing
|
102
|
if (m_pGridCtrl)
|
103
|
m_pGridCtrl->OnEndPrinting(pDC, pInfo);
|
104
|
|
105
|
|
106
|
}
|
107
|
|
108
|
/////////////////////////////////////////////////////////////////////////////
|
109
|
// CEhhevtView diagnostics
|
110
|
|
111
|
#ifdef _DEBUG
|
112
|
void CEhhevtView::AssertValid() const
|
113
|
{
|
114
|
CView::AssertValid();
|
115
|
}
|
116
|
|
117
|
void CEhhevtView::Dump(CDumpContext& dc) const
|
118
|
{
|
119
|
CView::Dump(dc);
|
120
|
}
|
121
|
|
122
|
|
123
|
#endif //_DEBUG
|
124
|
|
125
|
/////////////////////////////////////////////////////////////////////////////
|
126
|
// CEhhevtView message handlers
|
127
|
void CEhhevtView::OnInitialUpdate()
|
128
|
{
|
129
|
CView::OnInitialUpdate();
|
130
|
InitAllData();
|
131
|
// TODO: Add your specialized code here and/or call the base class
|
132
|
if (m_pGridCtrl == NULL)
|
133
|
{
|
134
|
// Create the Gridctrl object
|
135
|
m_pGridCtrl = new CGridCtrl;
|
136
|
if (!m_pGridCtrl) return;
|
137
|
|
138
|
// Create the Gridctrl window
|
139
|
CRect rect;
|
140
|
GetClientRect(rect);
|
141
|
m_pGridCtrl->Create(rect, this, 10001);
|
142
|
|
143
|
m_pGridCtrl->SetRowResize(FALSE);
|
144
|
|
145
|
m_pGridCtrl->SetVirtualMode(FALSE);
|
146
|
m_pGridCtrl->SetEditable(FALSE);
|
147
|
|
148
|
m_pGridCtrl->SetFixedRowSelection(TRUE);
|
149
|
m_pGridCtrl->SetListMode(TRUE);
|
150
|
m_pGridCtrl->EnableHiddenColUnhide(FALSE);
|
151
|
|
152
|
|
153
|
m_pGridCtrl->SetHeaderSort(TRUE);
|
154
|
m_pGridCtrl->SetCompareFunction(CGridCtrl::pfnCellNumericCompare);
|
155
|
|
156
|
|
157
|
HDC hDc = ::GetDC(HWND(NULL));
|
158
|
CFont * editFont = m_pGridCtrl->GetFont();
|
159
|
LOGFONT lf;
|
160
|
editFont->GetLogFont(&lf);
|
161
|
//lf.lfHeight = -13;
|
162
|
lf.lfHeight = -MulDiv(m_fontSize, GetDeviceCaps(hDc, LOGPIXELSY), 72);
|
163
|
strcpy(lf.lfFaceName, "???ź?");
|
164
|
m_editFont.CreateFontIndirect(&lf);
|
165
|
m_pGridCtrl->SetFont(&m_editFont);
|
166
|
::ReleaseDC(HWND(NULL),hDc);
|
167
|
|
168
|
SetGridColor();
|
169
|
InitGridHead();
|
170
|
}
|
171
|
|
172
|
}
|
173
|
|
174
|
void CEhhevtView::OnSize(UINT nType, int cx, int cy)
|
175
|
{
|
176
|
CView::OnSize(nType, cx, cy);
|
177
|
|
178
|
// TODO: Add your message handler code here
|
179
|
CRect rc;
|
180
|
GetClientRect(rc);
|
181
|
|
182
|
if(m_pGridCtrl->GetSafeHwnd())
|
183
|
{
|
184
|
rc.right = rc.right +2;
|
185
|
m_pGridCtrl->MoveWindow(rc);
|
186
|
|
187
|
CRect wrc;
|
188
|
GetWindowRect(&wrc);
|
189
|
wrc.OffsetRect(-wrc.left, -wrc.top);
|
190
|
wrc.DeflateRect(4, 0, 2, 0);
|
191
|
CRgn rgn;
|
192
|
BOOL bl = rgn.CreateRectRgnIndirect(&wrc);
|
193
|
if (bl)
|
194
|
{
|
195
|
SetWindowRgn(rgn, TRUE);
|
196
|
}
|
197
|
rgn.Detach();
|
198
|
}
|
199
|
|
200
|
|
201
|
}
|
202
|
|
203
|
BOOL CEhhevtView::InitGridHead()//??ͷ
|
204
|
{ //WYF 20180719 alarmset.ini-[??????] ????
|
205
|
CIn_hevtApp *pApp =(CIn_hevtApp *)AfxGetApp();
|
206
|
CReadConf cfg;
|
207
|
char szName[32]=""; //WYF 20180719
|
208
|
try
|
209
|
{
|
210
|
m_pGridCtrl->SetRowCount(m_nRows+1);
|
211
|
m_pGridCtrl->SetColumnCount(m_nCols+1);
|
212
|
m_pGridCtrl->SetFixedRowCount(m_nFixRows);
|
213
|
m_pGridCtrl->SetFixedColumnCount(m_nFixCols);
|
214
|
}
|
215
|
catch (CMemoryException* e)
|
216
|
{
|
217
|
e->ReportError();
|
218
|
e->Delete();
|
219
|
return FALSE;
|
220
|
}
|
221
|
// GV_ITEM ItemNum;
|
222
|
// ItemNum.row = 0;
|
223
|
// ItemNum.col = 0;
|
224
|
// ItemNum.mask |= GVIF_BKCLR;
|
225
|
// ItemNum.mask |= GVIF_FGCLR;
|
226
|
// ItemNum.crFgClr = RGB(0, 0, 0);
|
227
|
// ItemNum.crBkClr = RGB(255, 255, 255);
|
228
|
// m_pGridCtrl->SetItem(&ItemNum); ?̶??е?һ?д??ַ?ʽ??????Ҫ????????(??Ϊ?ո?)??????????ʱ????---add by sjw 2020.1.14
|
229
|
m_pGridCtrl->SetTextBkColor(g_pApp->m_GridBkColor);
|
230
|
m_pGridCtrl->SetItemBkColour(0, 0, RGB(255, 255, 255));
|
231
|
m_pGridCtrl->SetItemFgColour(0, 0, RGB(0, 0, 0));
|
232
|
for (int i = 0; i < m_nCols; i++)
|
233
|
{
|
234
|
GV_ITEM Item;
|
235
|
|
236
|
Item.mask = GVIF_TEXT;
|
237
|
Item.row = 0;
|
238
|
Item.col = i+1;
|
239
|
//WYF 20180719 alarmset.ini-[??????] ????
|
240
|
//cfg.ReadString("??ʷ??????", m_colType[i].szName, szName, pApp->m_szCfgPath, m_colType[i].szName);
|
241
|
Item.strText.Format("%s", m_colType[i].szDesc);//WYF 20180719 m_colType[i].szName);
|
242
|
Item.mask |= GVIF_BKCLR;
|
243
|
Item.mask |= GVIF_FGCLR;
|
244
|
Item.crFgClr = RGB(0, 0, 0);
|
245
|
Item.crBkClr = RGB(255, 255, 255);
|
246
|
m_pGridCtrl->SetItem(&Item);
|
247
|
}
|
248
|
SetAllColWidth();
|
249
|
|
250
|
return TRUE;
|
251
|
}
|
252
|
|
253
|
void CEhhevtView::SetAllColWidth()//col????
|
254
|
{
|
255
|
m_pGridCtrl->SetColumnWidth(0, 0);//30;wyf 20181102?̶??п?
|
256
|
for(int i = 0; i < m_nCols; i++)
|
257
|
{
|
258
|
long lWidth = m_colType[i].lWidth;
|
259
|
if(m_colType[i].bSet)
|
260
|
m_pGridCtrl->SetColumnWidth(i+1, lWidth);
|
261
|
else
|
262
|
m_pGridCtrl->SetColumnWidth(i+1, 0);
|
263
|
}
|
264
|
}
|
265
|
|
266
|
BOOL CEhhevtView::InitAllData()
|
267
|
{
|
268
|
CSE_DBOption dbo;
|
269
|
|
270
|
if (dbo.BeginSelectRcdSet(SQL_ALMH_FLD) != SEDB_SUCCESS)
|
271
|
return FALSE;
|
272
|
CIn_hevtApp *pApp =(CIn_hevtApp *)AfxGetApp();
|
273
|
CReadConf cfg;
|
274
|
COLTYPE ct;
|
275
|
char szWidth[MAX_PATH];
|
276
|
char width[10];
|
277
|
short datalen;
|
278
|
char nameDefine[2][32] = { "?Ƿ?ȷ??", "?Ƿ?ָ?" };
|
279
|
|
280
|
m_nCols = dbo.GetRcdCount();
|
281
|
m_nCols += 2; //+2??ʾnameDefine????
|
282
|
m_colType.SetSize(m_nCols);
|
283
|
for (int i = 0; i < m_nCols-2; i++)
|
284
|
{
|
285
|
|
286
|
strcpy(ct.szName, dbo.GetStringVal(i, 0));
|
287
|
int index = cfg.ReadLong("ColSequence",ct.szName,pApp->m_szCfgPath,0);
|
288
|
|
289
|
datalen = dbo.GetShortVal(i, 1);
|
290
|
sprintf(szWidth, "%s????", ct.szName);
|
291
|
sprintf(width, "%d", datalen > 0 ? min(datalen, 64) * 8 : 64);
|
292
|
ct.lWidth = cfg.ReadLong("History", szWidth, pApp->m_szCfgPath, width);
|
293
|
ct.bSet = cfg.ReadLong("History", ct.szName, pApp->m_szCfgPath, "0") != 0;
|
294
|
cfg.ReadString("??ʷ??????", ct.szName, ct.szDesc, pApp->m_szCfgPath, ct.szName);
|
295
|
|
296
|
m_colType[index] = ct;
|
297
|
}
|
298
|
for (i = 0; i < 2; i++)
|
299
|
{
|
300
|
|
301
|
strcpy(ct.szName, nameDefine[i]);
|
302
|
int index = cfg.ReadLong("ColSequence", ct.szName, pApp->m_szCfgPath, 0); //??֧???ظ?
|
303
|
sprintf(szWidth, "%s????", ct.szName);
|
304
|
ct.lWidth = cfg.ReadLong("History", szWidth, pApp->m_szCfgPath, "64");
|
305
|
ct.bSet = cfg.ReadLong("History", ct.szName, pApp->m_szCfgPath, "0") != 0;
|
306
|
cfg.ReadString("??ʷ??????", ct.szName, ct.szDesc, pApp->m_szCfgPath, nameDefine[i]);
|
307
|
|
308
|
m_colType[index] = ct;
|
309
|
}
|
310
|
m_fontSize = cfg.ReadLong("History","?????С",pApp->m_szCfgPath, "15");
|
311
|
|
312
|
dbo.EndSelectRcdSet();
|
313
|
return TRUE;
|
314
|
}
|
315
|
|
316
|
|
317
|
/*BOOL CEhhevtView::InitAllData()
|
318
|
{
|
319
|
CSE_DBOption dbo;
|
320
|
|
321
|
if (dbo.BeginSelectRcdSet(SQL_ALMH_FLD) != SEDB_SUCCESS)
|
322
|
return FALSE;
|
323
|
CEhhevtApp *pApp =(CEhhevtApp *)AfxGetApp();
|
324
|
CReadConf cfg;
|
325
|
COLTYPE ct;
|
326
|
char szWidth[MAX_PATH];
|
327
|
char width[10];
|
328
|
short datalen;
|
329
|
|
330
|
m_nCols = dbo.GetRcdCount();
|
331
|
|
332
|
m_colType.SetSize(m_nCols);
|
333
|
for (int i = 0; i < m_nCols; i++)
|
334
|
{
|
335
|
strcpy(ct.szName, dbo.GetStringVal(i, 0));
|
336
|
datalen = dbo.GetShortVal(i, 1);
|
337
|
|
338
|
sprintf(szWidth, "%s????", ct.szName);
|
339
|
sprintf(width, "%d", datalen > 0 ? min(datalen, 64) * 8 : 64);
|
340
|
ct.lWidth = cfg.ReadLong("History", szWidth, pApp->m_szCfgPath, width);
|
341
|
ct.bSet = cfg.ReadLong("History", ct.szName, pApp->m_szCfgPath, "1") != 0;
|
342
|
m_colType[i] = ct;
|
343
|
}
|
344
|
|
345
|
dbo.EndSelectRcdSet();
|
346
|
return TRUE;
|
347
|
}*/
|
348
|
|
349
|
void CEhhevtView::RefreshGrid()//?к?
|
350
|
{
|
351
|
long lCount = m_pGridCtrl->GetRowCount();
|
352
|
|
353
|
CString str;
|
354
|
for(long l = 1; l < lCount; l++)
|
355
|
{
|
356
|
str.Format("%d", l);
|
357
|
m_pGridCtrl->SetItemText(l, 0, str);
|
358
|
}
|
359
|
}
|
360
|
|
361
|
void CEhhevtView::OnGridSizingCol()
|
362
|
{
|
363
|
long lWidth;
|
364
|
char szKey[MAX_PATH];
|
365
|
char szWidth[MAX_PATH];
|
366
|
|
367
|
int nCol = m_colType.GetSize();
|
368
|
for(int i = 1; i <= nCol; i++)
|
369
|
{
|
370
|
if (!m_colType[i-1].bSet)
|
371
|
continue;
|
372
|
|
373
|
lWidth = m_pGridCtrl->GetColumnWidth(i);
|
374
|
if (m_colType[i-1].lWidth == lWidth)
|
375
|
continue;
|
376
|
|
377
|
m_colType[i-1].lWidth = lWidth;
|
378
|
|
379
|
sprintf(szKey, "%s????", m_colType[i-1].szName);
|
380
|
sprintf(szWidth, "%d", lWidth);
|
381
|
::WritePrivateProfileString("History", szKey, szWidth, g_pApp->m_szCfgPath);
|
382
|
}
|
383
|
}
|
384
|
|
385
|
void CEhhevtView::SetGridColor()
|
386
|
{
|
387
|
m_pGridCtrl->SetGridBkColor(g_pApp->m_GridBkColor);
|
388
|
m_pGridCtrl->SetGridLineColor(g_pApp->m_GridLineColor);
|
389
|
}
|