📄 qssreadbotdlg.cpp
字号:
strDBConnection += strDatabaseName + ";UID=" + strUserID ;
strDBConnection += ";PWD=" + strUserPassword ;
try
{
hr = m_pConnection.CreateInstance("ADODB.Connection"); /// 创建Connection对象
if(SUCCEEDED(hr))
{
// 设置通讯超时(一天时间)
m_pConnection->ConnectionTimeout = 1000 ;
hr = m_pConnection->Open( (_bstr_t)strDBConnection, "", "", adModeUnknown );
if ( S_OK != hr )
AfxMessageBox("数据库连接失败!") ;
}
else
return -12 ;
}
catch(_com_error e) /// 捕捉异常
{
CString errormessage;
errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage); /// 显示错误信息
}
// 读取空调基本信息
_RecordsetPtr m_pRecordset ;
CString strSql ; // "SELECT * FROM T_AC_Equipment WHERE Equipment_Kind = '0' AND Equipment_QSS = '" + strQssNumber + "' ";
CString strQssNumber,tt ;
_variant_t vEquipmentID ;
char szQssNumber[4] ;
// CString strEquipementID[10][48] ;
// int nEquipementCount[10] ;
hr = m_pRecordset.CreateInstance( "ADODB.Recordset" ) ;
if ( S_OK != hr )
AfxMessageBox("生成'Recordset'记录集错误!") ;
try
{
if(m_pConnection->State) // adLockReadOnly, adLockOptimistic
{
for (int j = 0 ; j < 10 ; j ++ )
{
i = 0 ;
itoa( j+1, szQssNumber, 10 ) ;
strQssNumber = szQssNumber ;
strSql = "SELECT * FROM T_AC_Equipment WHERE Equipment_Kind = '0' AND Equipment_QSS = '" + strQssNumber + "' ";
hr = m_pRecordset->Open( (_bstr_t) strSql, _variant_t((IDispatch*)m_pConnection,true), adOpenStatic, adLockReadOnly, adCmdText);
if ( S_OK != hr )
AfxMessageBox("打开记录集'Recordset'错误!") ;
while( !m_pRecordset->adoEOF )
{
/// vEquipmentID = m_pRecordset->GetCollect( _variant_t((long)0) ) ; /// 取得第 1 列的值,从 0 开始计数
vEquipmentID = m_pRecordset->GetCollect( "Equipment_ID" ) ; /// 取得 Equipment_ID 字段的值
strEquipementID[j][i] = vEquipmentID.bstrVal ;
tt = strEquipementID[j][i] ;
if ( strEquipementID[j][i].GetLength() != 6 )
{
AfxMessageBox("错误: 取得的空调编号长度错误!!" ) ;
}
i++ ;
hr = m_pRecordset->MoveNext() ;
if ( S_OK != hr )
AfxMessageBox("'Recordset'记录集移动错误错误!") ;
}
nEquipementCount[j] = i ;
m_pRecordset->Close() ;
}
}
}
catch(_com_error e) /// 捕捉异常
{
CString errormessage;
errormessage.Format("读取数据库空调信息失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage); /// 显示错误信息
}
// 最小化对话框
//SendMessage( WM_SIZE, SIZE_MINIMIZED, 0 ) ;
//SendDlgItemMessage( IDOK, WM_LBUTTONDOWN, 0 , 0) ;
// 设置主线程定时器定时管理 Qss 数据采集线程函数和 Socket 通信线程
SetTimer( ID_TIMER0, 1000, NULL ) ;//????????????????
///////////////////////////////////////////////////////////////////////////
return TRUE; // return TRUE unless you set the focus to a control
}
void CQssReadBotDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CQssReadBotDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CQssReadBotDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CQssReadBotDlg::OnClose()
{
// 释放临街区
DeleteCriticalSection( &criticalSection ) ;
//
//if(m_pConnection->State)
// m_pConnection->Close() ;
//CoUninitialize() ;
// 托盘程序操作
//if (m_bShutdown)
// CQssReadBotDlg::OnClose();
CDialog::OnClose();
}
void CQssReadBotDlg::OnSetqss()
{
DWORD dwRet = 0 ;
// 挂起所有线程
SuspendThread( hHandleQSS1 ) ;
SuspendThread( hHandleQSS2 ) ;
SuspendThread( hHandleQSS3 ) ;
SuspendThread( hHandleQSS4 ) ;
SuspendThread( hHandleQSS5 ) ;
SuspendThread( hHandleQSS6 ) ;
SuspendThread( hHandleQSS7 ) ;
SuspendThread( hHandleQSS8 ) ;
SuspendThread( hHandleQSS9 ) ;
SuspendThread( hHandleQSS10 ) ;
// 设置QSS线程开关读取
//CString strQSS[10] ;
//CString strCom ;
GetDlgItemText(IDC_COMBO1, strQSS[0] ) ;
GetDlgItemText(IDC_COMBO2, strQSS[1] ) ;
GetDlgItemText(IDC_COMBO3, strQSS[2] ) ;
GetDlgItemText(IDC_COMBO4, strQSS[3] ) ;
GetDlgItemText(IDC_COMBO5, strQSS[4] ) ;
GetDlgItemText(IDC_COMBO6, strQSS[5] ) ;
GetDlgItemText(IDC_COMBO7, strQSS[6] ) ;
GetDlgItemText(IDC_COMBO8, strQSS[7] ) ;
GetDlgItemText(IDC_COMBO9, strQSS[8] ) ;
GetDlgItemText(IDC_COMBO10, strQSS[9] ) ;
// 得到 Check 检查标志
int nCheckRet[10] ;
nCheckRet[0] = m_Check1.GetCheck() ;
nCheckRet[1] = m_Check2.GetCheck() ;
nCheckRet[2] = m_Check3.GetCheck() ;
nCheckRet[3] = m_Check4.GetCheck() ;
nCheckRet[4] = m_Check5.GetCheck() ;
nCheckRet[5] = m_Check6.GetCheck() ;
nCheckRet[6] = m_Check7.GetCheck() ;
nCheckRet[7] = m_Check8.GetCheck() ;
nCheckRet[8] = m_Check9.GetCheck() ;
nCheckRet[9] = m_Check10.GetCheck() ;
if ( nCheckRet[0] == 1 && !(strQSS[0].IsEmpty()) )
{
do{
dwRet = ResumeThread( hHandleQSS1 ) ;
}while ( dwRet != 0 ) ;
}
if ( nCheckRet[1] == 1 && !(strQSS[1].IsEmpty()) )
{
do{
dwRet = ResumeThread( hHandleQSS2 ) ;
}while ( dwRet != 0 ) ;
}
if ( nCheckRet[2] == 1 && !(strQSS[2].IsEmpty()) )
{
do{
dwRet = ResumeThread( hHandleQSS3 ) ;
}while ( dwRet != 0 ) ;
}
if ( nCheckRet[3] == 1 && !(strQSS[3].IsEmpty()) )
{
do{
dwRet = ResumeThread( hHandleQSS4 ) ;
}while ( dwRet != 0 ) ;
}
if ( nCheckRet[4] == 1 && !(strQSS[4].IsEmpty()) )
{
do{
dwRet = ResumeThread( hHandleQSS5 ) ;
}while ( dwRet != 0 ) ;
}
if ( nCheckRet[5] == 1 && !(strQSS[5].IsEmpty()) )
{
do{
dwRet = ResumeThread( hHandleQSS6 ) ;
}while ( dwRet != 0 ) ;
}
if ( nCheckRet[6] == 1 && !(strQSS[6].IsEmpty()) )
{
do{
dwRet = ResumeThread( hHandleQSS7 ) ;
}while ( dwRet != 0 ) ;
}
if ( nCheckRet[7] == 1 && !(strQSS[7].IsEmpty()) )
{
do{
dwRet = ResumeThread( hHandleQSS8 ) ;
}while ( dwRet != 0 ) ;
}
if ( nCheckRet[8] == 1 && !(strQSS[8].IsEmpty()) )
{
do{
dwRet = ResumeThread( hHandleQSS9 ) ;
}while ( dwRet != 0 ) ;
}
if ( nCheckRet[9] == 1 && !(strQSS[9].IsEmpty()) )
{
do{
dwRet = ResumeThread( hHandleQSS10 ) ;
}while ( dwRet != 0 ) ;
}
/* // 恢复线程
ResumeThread( hHandleQSS1 ) ;
ResumeThread( hHandleQSS2 ) ;
ResumeThread( hHandleQSS3 ) ;
ResumeThread( hHandleQSS4 ) ;
ResumeThread( hHandleQSS5 ) ;
ResumeThread( hHandleQSS6 ) ;
ResumeThread( hHandleQSS7 ) ;
ResumeThread( hHandleQSS8 ) ;
ResumeThread( hHandleQSS9 ) ;
ResumeThread( hHandleQSS10 ) ;
*/
return ;
}
void CQssReadBotDlg::OnCheckall()
{
// TODO: Add your control notification handler code here
int nCheckRet = -1 ;
nCheckRet = m_CheckAll.GetCheck() ;
switch ( nCheckRet )
{
case 0:
m_Check1.SetCheck( 0 ) ;
m_Check2.SetCheck( 0 ) ;
m_Check3.SetCheck( 0 ) ;
m_Check4.SetCheck( 0 ) ;
m_Check5.SetCheck( 0 ) ;
m_Check6.SetCheck( 0 ) ;
m_Check7.SetCheck( 0 ) ;
m_Check8.SetCheck( 0 ) ;
m_Check9.SetCheck( 0 ) ;
m_Check10.SetCheck( 0 ) ;
break ;
case 1:
m_Check1.SetCheck( 1 ) ;
m_Check2.SetCheck( 1 ) ;
m_Check3.SetCheck( 1 ) ;
m_Check4.SetCheck( 1 ) ;
m_Check5.SetCheck( 1 ) ;
m_Check6.SetCheck( 1 ) ;
m_Check7.SetCheck( 1 ) ;
m_Check8.SetCheck( 1 ) ;
m_Check9.SetCheck( 1 ) ;
m_Check10.SetCheck( 1 ) ;
break ;
case 2:
m_Check1.SetCheck( 2 ) ;
m_Check2.SetCheck( 2 ) ;
m_Check3.SetCheck( 2 ) ;
m_Check4.SetCheck( 2 ) ;
m_Check5.SetCheck( 2 ) ;
m_Check6.SetCheck( 2 ) ;
m_Check7.SetCheck( 2 ) ;
m_Check8.SetCheck( 2 ) ;
m_Check9.SetCheck( 2 ) ;
m_Check10.SetCheck( 2 ) ;
break ;
}
}
void CQssReadBotDlg::OnCancelqss()
{
return ;
}
////////////////////////////////////////////////////////////////////////////////////
/****************************************************************************/
// //
// 线程函数和线程管理函数 //
// //
// 时间:2005-01-18 作者:Jason //
// //
// //
/****************************************************************************/
//===============================================================
LRESULT CALLBACK Thread1( void )
{
HINSTANCE hInstance = AfxGetApp()->m_hInstance ;
// 主窗口操作
HWND hWnd = NULL ;
LPCTSTR lpszClassName = "QssThread1" ;
LPCTSTR lpszTitle = "QssThread1" ;
// 设置背景画刷( WHITE_BRUSH )
HBRUSH hBrush = (HBRUSH)GetStockObject( GRAY_BRUSH );
HICON hIcon = LoadIcon( NULL, IDI_APPLICATION );
HCURSOR hCursor = LoadCursor( NULL, IDC_ARROW );
MSG Msg;
WNDCLASS wndClass;
// 窗口类定义
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hbrBackground = hBrush;
wndClass.hCursor = hCursor;
wndClass.hIcon = hIcon;
wndClass.hInstance = hInstance;
wndClass.lpfnWndProc = (WNDPROC)OnThreadProc1;
wndClass.lpszClassName = lpszClassName ;
wndClass.lpszMenuName = NULL;
wndClass.style = CS_HREDRAW|CS_VREDRAW;
// 窗口类注册
if ( !RegisterClass( &wndClass ))
{
MessageBeep( 0 ) ;
return FALSE ;
}
// 创建窗口
hWnd = CreateWindow( lpszClassName, // 窗口类名
lpszTitle, // 窗口实例标题名
WS_OVERLAPPEDWINDOW, // 窗口风格
CW_USEDEFAULT, //
CW_USEDEFAULT, // 窗口作上角坐标为缺省值
CW_USEDEFAULT,
CW_USEDEFAULT, // 窗口宽高为缺省值
NULL, // 此窗口无主窗口
NULL, // 此主窗口无菜单
hInstance, // 创建此窗口的应用程序的当前句柄
NULL ) ; // 消息 WM_CREATE 通过 CREATESTRUCT 结构传递过来的 lParam 参数
if ( NULL == hWnd )
{
DWORD dwRet = GetLastError() ;
return FALSE ;
}
// 显示窗口( nShowCmd )
//ShowWindow( hWnd, SW_SHOWMAXIMIZED ) ; // 最大化窗口
//ShowWindow( hWnd, SW_SHOW ) ;
// 绘制用户区
//UpdateWindow( hWnd ) ;
SetTimer( hWnd, ID_TIMER1, uTimerElapse, NULL ) ;
// 消息循环
while( GetMessage( &Msg, NULL, 0, 0 ) )
{
TranslateMessage( &Msg ) ;
DispatchMessage( &Msg ) ;
}
return Msg.wParam ; // 消息循环结束(程序终止)时将消息返回系统
}
//===============================================================
LRESULT CALLBACK Thread2( void )
{
HINSTANCE hInstance = AfxGetApp()->m_hInstance ;
// 主窗口操作
HWND hWnd = NULL ;
LPCTSTR lpszClassName = "QssThread2" ;
LPCTSTR lpszTitle = "QssThread2" ;
// 设置背景画刷( WHITE_BRUSH )
HBRUSH hBrush = (HBRUSH)GetStockObject( GRAY_BRUSH );
HICON hIcon = LoadIcon( NULL, IDI_APPLICATION );
HCURSOR hCursor = LoadCursor( NULL, IDC_ARROW );
MSG Msg;
WNDCLASS wndClass;
// 窗口类定义
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hbrBackground = hBrush;
wndClass.hCursor = hCursor;
wndClass.hIcon = hIcon;
wndClass.hInstance = hInstance;
wndClass.lpfnWndProc = (WNDPROC)OnThreadProc2;
wndClass.lpszClassName = lpszClassName ;
wndClass.lpszMenuName = NULL;
wndClass.style = CS_HREDRAW|CS_VREDRAW;
// 窗口类注册
if ( !RegisterClass( &wndClass ))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -