提交 | 用户 | age
|
418cb3
|
1 |
// CDialogEventLog.cpp: 实现文件
|
Q |
2 |
//
|
|
3 |
|
|
4 |
#include "pch.h"
|
|
5 |
#include "MTerm1.h"
|
|
6 |
#include "DialogEventLog.h"
|
|
7 |
#include "afxdialogex.h"
|
|
8 |
#include "KLinkDefine.h"
|
|
9 |
//#include "KLink.h"
|
|
10 |
#include "MTerm1Doc.h"
|
|
11 |
// CDialogEventLog 对话框
|
|
12 |
|
|
13 |
IMPLEMENT_DYNAMIC(CDialogEventLog, CDialogEx)
|
|
14 |
|
|
15 |
CDialogEventLog::CDialogEventLog(CWnd* pParent /*=nullptr*/)
|
|
16 |
: CDialogEx(IDD_DIALOG_EVENTLOG, pParent)
|
|
17 |
{
|
|
18 |
|
|
19 |
}
|
|
20 |
|
|
21 |
CDialogEventLog::~CDialogEventLog()
|
|
22 |
{
|
|
23 |
}
|
|
24 |
|
|
25 |
void CDialogEventLog::DoDataExchange(CDataExchange* pDX)
|
|
26 |
{
|
|
27 |
CDialogEx::DoDataExchange(pDX);
|
|
28 |
DDX_Control(pDX, IDC_LIST_EVENTLOG, m_list_eventlog);
|
|
29 |
}
|
|
30 |
|
|
31 |
|
|
32 |
BEGIN_MESSAGE_MAP(CDialogEventLog, CDialogEx)
|
|
33 |
ON_BN_CLICKED(IDC_BUTTON_CLEAR_EVENTLOG, &CDialogEventLog::OnBnClickedButtonClearEventlog)
|
|
34 |
ON_BN_CLICKED(IDC_BUTTON_RELOAD, &CDialogEventLog::OnBnClickedButtonReload)
|
|
35 |
ON_WM_TIMER()
|
|
36 |
END_MESSAGE_MAP()
|
|
37 |
|
|
38 |
KLink1::stEventLog KEventLogs[20000];
|
|
39 |
|
|
40 |
// CDialogEventLog 消息处理程序
|
|
41 |
void CDialogEventLog::OnBnClickedButtonReload()
|
|
42 |
{
|
|
43 |
// TODO: 在此添加控件通知处理程序代码
|
|
44 |
GetEventLogStatus();
|
|
45 |
UpLoadEventLog();
|
|
46 |
}
|
|
47 |
|
|
48 |
void CDialogEventLog::OnBnClickedButtonClearEventlog()
|
|
49 |
{
|
|
50 |
// TODO: 在此添加控件通知处理程序代码
|
|
51 |
}
|
|
52 |
|
|
53 |
|
|
54 |
int CDialogEventLog::GetEventLogStatus()
|
|
55 |
{
|
|
56 |
// TODO: 在此处添加实现代码.
|
|
57 |
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
|
|
58 |
CMDIChildWnd *pChild = (CMDIChildWnd *)pFrame->GetActiveFrame();
|
|
59 |
CView *pV = (CView*)pChild->GetActiveView();
|
|
60 |
CMTerm1Doc* pDoc = (CMTerm1Doc *)(pV->GetDocument());
|
|
61 |
|
|
62 |
int nCount;
|
61deef
|
63 |
int res = theApp.MyKLink1.GetEventLogCount(1, &nCount);
|
418cb3
|
64 |
CString s1;
|
Q |
65 |
|
|
66 |
s1.Format(_T("Get EventLogCount Result r=%d N=%d "), res, nCount);
|
|
67 |
SysLog(s1);
|
61deef
|
68 |
if (res == theApp.MyKLink1.KL_OK)
|
418cb3
|
69 |
{
|
Q |
70 |
s1.Format(_T("%d"), nCount);
|
|
71 |
GetDlgItem(IDC_EDIT_EVENT_COUNT)->SetWindowText(s1);
|
|
72 |
}
|
|
73 |
|
|
74 |
return 0;
|
|
75 |
}
|
|
76 |
|
|
77 |
int CDialogEventLog::UpLoadEventLog()
|
|
78 |
{
|
|
79 |
// TODO: 在此处添加实现代码.
|
|
80 |
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
|
|
81 |
CMDIChildWnd *pChild = (CMDIChildWnd *)pFrame->GetActiveFrame();
|
|
82 |
CView *pV = (CView*)pChild->GetActiveView();
|
|
83 |
CMTerm1Doc* pDoc = (CMTerm1Doc *)(pV->GetDocument());
|
|
84 |
|
|
85 |
int nCount;
|
61deef
|
86 |
int res = theApp.MyKLink1.GetEventLogCount(1, &nCount);
|
418cb3
|
87 |
CString s1;
|
Q |
88 |
|
|
89 |
s1.Format(_T("Get EventLogCount Result r=%d N=%d "), res, nCount);
|
|
90 |
SysLog(s1);
|
|
91 |
|
61deef
|
92 |
if (res == theApp.MyKLink1.KL_OK)
|
418cb3
|
93 |
{
|
Q |
94 |
s1.Format(_T("%d"), nCount);
|
|
95 |
GetDlgItem(IDC_EDIT_EVENT_COUNT)->SetWindowText(s1);
|
|
96 |
}
|
|
97 |
int nStartIndex = 0;
|
|
98 |
int nReadCount = 1;
|
|
99 |
m_list_eventlog.DeleteAllItems();
|
|
100 |
|
|
101 |
m_nEventCount = nCount;
|
|
102 |
m_nCurEvent = 0;
|
df0321
|
103 |
SetTimer(1, 50, NULL);
|
418cb3
|
104 |
// for (int i = 0; i < nCount; i++)
|
Q |
105 |
// {
|
|
106 |
// GetEventLogByIndex(i);
|
|
107 |
// }
|
|
108 |
|
|
109 |
return 0;
|
|
110 |
}
|
|
111 |
|
|
112 |
|
|
113 |
BOOL CDialogEventLog::OnInitDialog()
|
|
114 |
{
|
|
115 |
CDialogEx::OnInitDialog();
|
|
116 |
|
|
117 |
// TODO: 在此添加额外的初始化
|
|
118 |
m_list_eventlog.SetExtendedStyle(LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_ONECLICKACTIVATE | LVS_EX_LABELTIP);
|
|
119 |
m_list_eventlog.DeleteAllItems();
|
|
120 |
while (m_list_eventlog.DeleteColumn(0));
|
|
121 |
m_list_eventlog.InsertColumn(0, _T("NO"), LVCFMT_LEFT, 32, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER
|
|
122 |
m_list_eventlog.InsertColumn(1, _T("序列号"), LVCFMT_LEFT, 48, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER
|
|
123 |
m_list_eventlog.InsertColumn(2, _T("时间"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER
|
|
124 |
m_list_eventlog.InsertColumn(3, _T("类型"), LVCFMT_LEFT, 64, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER
|
|
125 |
m_list_eventlog.InsertColumn(4, _T("数据1"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER
|
|
126 |
m_list_eventlog.InsertColumn(5, _T("数据2"), LVCFMT_LEFT, 128, -1);//LVCFMT_LEFT, LVCFMT_RIGHT, or LVCFMT_CENTER
|
|
127 |
|
|
128 |
SetTimer(0, 10, NULL);
|
|
129 |
return TRUE; // return TRUE unless you set the focus to a control
|
|
130 |
// 异常: OCX 属性页应返回 FALSE
|
|
131 |
}
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
int CDialogEventLog::DelayInit()
|
|
136 |
{
|
|
137 |
// TODO: 在此处添加实现代码.
|
|
138 |
GetEventLogStatus();
|
|
139 |
UpLoadEventLog();
|
|
140 |
return 0;
|
|
141 |
}
|
|
142 |
|
|
143 |
|
|
144 |
int CDialogEventLog::GetEventLogByIndex(int nIndex)
|
|
145 |
{
|
|
146 |
// TODO: 在此处添加实现代码.
|
|
147 |
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
|
|
148 |
CMDIChildWnd *pChild = (CMDIChildWnd *)pFrame->GetActiveFrame();
|
|
149 |
CView *pV = (CView*)pChild->GetActiveView();
|
|
150 |
CMTerm1Doc* pDoc = (CMTerm1Doc *)(pV->GetDocument());
|
|
151 |
|
|
152 |
int nReadCount = 1;
|
|
153 |
int res;
|
|
154 |
CString s1;
|
|
155 |
|
61deef
|
156 |
res = theApp.MyKLink1.GetEventLog(1, nIndex, nReadCount, &KEventLogs[nIndex]);
|
418cb3
|
157 |
s1.Format(_T(" Get EventLog %d Result r=%d "), nIndex, res);
|
Q |
158 |
s1.AppendFormat(_T("%d %d %d %d %d %d"), KEventLogs[nIndex].Sign1, KEventLogs[nIndex].Seq1, KEventLogs[nIndex].nTime, KEventLogs[nIndex].nType, KEventLogs[nIndex].nParam1, KEventLogs[nIndex].nParam2);
|
|
159 |
// SysLog(s1);
|
|
160 |
s1.Format(_T("%d"), nIndex);
|
|
161 |
m_list_eventlog.InsertItem(nIndex, s1);
|
|
162 |
s1.Format(_T("%d"), KEventLogs[nIndex].Seq1);
|
|
163 |
m_list_eventlog.SetItemText(nIndex, 1, s1);
|
|
164 |
|
|
165 |
s1.Format(_T("%d"), KEventLogs[nIndex].nTime);
|
|
166 |
CTime ctime1 = KEventLogs[nIndex].nTime;
|
|
167 |
s1 = ctime1.Format(_T("%Y-%m-%d %H:%M:%S"));
|
|
168 |
|
|
169 |
m_list_eventlog.SetItemText(nIndex, 2, s1);
|
|
170 |
s1.Format(_T("%d"), KEventLogs[nIndex].nType);
|
|
171 |
m_list_eventlog.SetItemText(nIndex, 3, s1);
|
|
172 |
s1.Format(_T("%d"), KEventLogs[nIndex].nParam1);
|
|
173 |
m_list_eventlog.SetItemText(nIndex, 4, s1);
|
|
174 |
s1.Format(_T("%d"), KEventLogs[nIndex].nParam2);
|
|
175 |
m_list_eventlog.SetItemText(nIndex, 5, s1);
|
|
176 |
//m_list_eventlog.SetItemText(nIndex, 5, s1);
|
|
177 |
return 0;
|
|
178 |
}
|
|
179 |
|
|
180 |
|
|
181 |
void CDialogEventLog::OnTimer(UINT_PTR nIDEvent)
|
|
182 |
{
|
|
183 |
// TODO: 在此添加消息处理程序代码和/或调用默认值
|
|
184 |
if (nIDEvent == 0) {
|
|
185 |
KillTimer(0);
|
|
186 |
DelayInit();
|
|
187 |
}
|
|
188 |
else if (nIDEvent == 1) {
|
|
189 |
|
|
190 |
GetEventProcess();
|
|
191 |
}
|
|
192 |
else
|
|
193 |
{
|
|
194 |
|
|
195 |
}
|
|
196 |
CDialogEx::OnTimer(nIDEvent);
|
|
197 |
}
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
int CDialogEventLog::GetEventProcess()
|
|
202 |
{
|
|
203 |
// TODO: 在此处添加实现代码.
|
|
204 |
if (m_nCurEvent < m_nEventCount)
|
|
205 |
{
|
|
206 |
GetEventLogByIndex(m_nCurEvent);
|
|
207 |
m_nCurEvent++;
|
|
208 |
if (m_nCurEvent >= m_nEventCount) { KillTimer(1); }
|
|
209 |
}
|
|
210 |
return 0;
|
|
211 |
}
|