📄 sqldatebase.cpp
字号:
// SQLDatebase.cpp: implementation of the CSQLDatebase class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SQLDatebase.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CSQLDatebase::CSQLDatebase()
{
HKEY hKey;
char lpstrValue[100], lpszMessage[100];
DWORD cbData = 100, dwType;
unsigned long dwRtValue;
if(RegOpenKeyEx(HKEY_CURRENT_USER, "software\\doggle\\AirGuard\\DataBase", 0, KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS)
MessageBox(NULL, "Calling RegOpenKeyEx error", "error", MB_OK | MB_ICONERROR);
dwRtValue = RegQueryValueEx(hKey, "ServerName", NULL, &dwType, (LPBYTE)lpstrValue, &cbData);
if (dwRtValue != ERROR_SUCCESS){
sprintf(lpszMessage, "找不到指定文件, 请与供应商联系");
MessageBox(NULL, lpszMessage, "error", MB_OK | MB_ICONERROR);
return;
}
if (strlen(lpstrValue) <= 20)
strcpy(lpszServerName, lpstrValue);
else MessageBox(NULL, "Regester error", "error", MB_OK | MB_ICONSTOP);
cbData = 100;
dwRtValue = RegQueryValueEx(hKey, "Workstation", NULL, &dwType, (LPBYTE)lpstrValue, &cbData);
if (dwRtValue != ERROR_SUCCESS){
sprintf(lpszMessage, "找不到指定文件, 请与供应商联系");
MessageBox(NULL, lpszMessage, "error", MB_OK | MB_ICONERROR);
return;
}
if (strlen(lpstrValue) <= 20)
strcpy(lpszHostName, lpstrValue);
else MessageBox(NULL, "Regester error", "error", MB_OK | MB_ICONSTOP);
cbData = 100;
dwRtValue = RegQueryValueEx(hKey, "UserName", NULL, &dwType, (LPBYTE)lpstrValue, &cbData);
if (dwRtValue != ERROR_SUCCESS){
sprintf(lpszMessage, "找不到指定文件, 请与供应商联系");
MessageBox(NULL, lpszMessage, "error", MB_OK | MB_ICONERROR);
return;
}
if (strlen(lpstrValue) <= 20)
strcpy(lpszUserName, lpstrValue);
else MessageBox(NULL, "Regester error", "error", MB_OK | MB_ICONSTOP);
cbData = 100;
dwRtValue = RegQueryValueEx(hKey, "Password", NULL, &dwType, (LPBYTE)lpstrValue, &cbData);
if (dwRtValue != ERROR_SUCCESS){
sprintf(lpszMessage, "找不到指定文件, 请与供应商联系");
MessageBox(NULL, lpszMessage, "error", MB_OK | MB_ICONERROR);
return;
}
if (strlen(lpstrValue) <= 20)
strcpy(lpszPassword, lpstrValue);
else MessageBox(NULL, "Regester error", "error", MB_OK | MB_ICONSTOP);
cbData = 100;
dwRtValue = RegQueryValueEx(hKey, "TimeLimit", NULL, &dwType, (LPBYTE)lpstrValue, &cbData);
if (dwRtValue != ERROR_SUCCESS){
sprintf(lpszMessage, "找不到指定文件, 请与供应商联系");
MessageBox(NULL, lpszMessage, "error", MB_OK | MB_ICONERROR);
return;
}
if (strlen(lpstrValue) <= 20)
dwTimeLimit = (DWORD)atoi(lpstrValue);
else MessageBox(NULL, "Regester error", "error", MB_OK | MB_ICONSTOP);
cbData = 100;
dwRtValue = RegQueryValueEx(hKey, "DataBaseManager", NULL, &dwType, (LPBYTE)lpstrValue, &cbData);
if (dwRtValue != ERROR_SUCCESS){
// FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwRtValue, 0, lpszMessage, 100, NULL);
sprintf(lpszMessage, "找不到指定文件, 请与供应商联系");
MessageBox(NULL, lpszMessage, "error", MB_OK | MB_ICONERROR);
return;
}
else strcpy(lpszDataBaseManagerPath, lpstrValue);
RegCloseKey(hKey);
}
bool CSQLDatebase::QueryDate(DBDATETIME *pDateTime)
// Function: Get the present date and time.
{
LOGINREC* login;
DBPROCESS* dbproc;
DBCHAR mbid[10] = "abc";
DBREAL hdz = 5;
DBREAL mld = 10;
char lpstrImage[100];
RETCODE row_code;
for (int i = 0; i < 100; i++)
lpstrImage[i] = 'f';
if(!dbinit())
MessageBox(NULL, "dbinit() error", "Datebase error", MB_OK | MB_ICONSTOP);
// dberrhandle(error_handler);
// dbmsghandle(message_handler);
if((login = dblogin()) == NULL)
MessageBox(NULL, "dbinit() error", "Datebase error", MB_OK | MB_ICONSTOP);
DBSETLUSER(login, lpszUserName);
DBSETLPWD(login, lpszPassword);
DBSETLHOST(login, lpszHostName);
DBSETLTIME(login, dwTimeLimit);
if((dbproc = dbopen(login, lpszServerName)) == NULL){
MessageBox(NULL, "dbinit() error", "Datebase error", MB_OK | MB_ICONSTOP);
return 0;
}
dbcmd(dbproc, "SELECT GETDATE()");
dbsqlexec(dbproc);
dbresults(dbproc);
while((row_code = dbnextrow(dbproc)) != NO_MORE_ROWS){
// dbconvert(dbproc, dbcoltype(dbproc, 1), dbdata(dbproc, 1),
// dbdatlen(dbproc, 1), SQLCHAR, lpszMessage, -1);
*pDateTime = (*(DBDATETIME*)dbdata(dbproc, 1));
}
dbexit();
return 1;
}
bool CSQLDatebase::ReadResult(DBREAL *pdbrBlackness, char *lpstrImage, DWORD *dwImageSize)
// Function: Get information of illegal events stored in database.
{
/* LOGINREC* login;
DBPROCESS* dbproc;
DBCHAR mbid[10] = "abc";
DBDATETIME jcsj = {2000, 1111};
DBREAL hdz = 5;
DBREAL mld = 10;
char lpstrImage[100];
RETCODE row_code;
DBCHAR chDate;
unsigned char lpszMessage[200];
char *pImage;
for (int i = 0; i < 100; i++)
lpstrImage[i] = 'f';
if(!dbinit())
MessageBox(NULL, "dbinit() error", "Datebase error", MB_OK | MB_ICONSTOP);
dberrhandle(error_handler);
dbmsghandle(message_handler);
if((login = dblogin()) == NULL)
MessageBox(NULL, "dbinit() error", "Datebase error", MB_OK | MB_ICONSTOP);
DBSETLUSER(login, "hd");
DBSETLPWD(login, "hd");
if((dbproc = dbopen(login, NULL)) == NULL){
MessageBox(NULL, "dbinit() error", "Datebase error", MB_OK | MB_ICONSTOP);
return 0;
}
dbcmd(dbproc, "SELECT tx FROM jcqk");
dbsqlexec(dbproc);
dbresults(dbproc);
while((row_code = dbnextrow(dbproc)) != NO_MORE_ROWS){
pImage = ((char*)dbdata(dbproc, 1));
for (int i = 0; i < 10; i ++)
lpszMessage[i] = *((char*)((DWORD)pImage + i));
lpszMessage[10] = '\0';
MessageBox(NULL, (LPSTR)lpszMessage, "Message", MB_OK);
}
dbexit();*/
return 1;
}
bool CSQLDatebase::WriteResult(DBREAL db_rBlackness, char *lpstrImage, DWORD dwImageSize, int iObjectID, int nCameraID)
// Function: Save information of an illegal even violating emission control regulations.
// The information include blackness, image, date and time, etc.
{
LOGINREC* login;
DBPROCESS* dbproc;
//DBCHAR mbid[10] ;
DBINT cameraid = nCameraID;
//sprintf(mbid, "Chimney%d", iObjectID);
DBDATETIME jcsj ;
DBREAL hdz = db_rBlackness;
DBREAL mld = 10;
DBINT dealed = 0;
QueryDate(&jcsj);
if(!dbinit())
MessageBox(NULL, "dbinit() error", "Datebase error", MB_OK | MB_ICONSTOP);
// dberrhandle(error_handler);
// dbmsghandle(message_handler);
if((login = dblogin()) == NULL)
MessageBox(NULL, "dbinit() error", "Datebase error", MB_OK | MB_ICONSTOP);
DBSETLUSER(login, lpszUserName);
DBSETLPWD(login, lpszPassword);
BCP_SETL(login, TRUE);
if((dbproc = dbopen(login, lpszServerName)) == NULL)
MessageBox(NULL, "dbinit() error", "Datebase error", MB_OK | MB_ICONSTOP);
// initiating bcp operation...
if (bcp_init(dbproc, "jcqk"/*"Object"*/, NULL, NULL, DB_IN) == FAIL)
return 0;
// designate variables for mbid
if (bcp_bind(dbproc, (BYTE*) &iObjectID, 0, (DBINT)-1, (LPCBYTE) NULL, 0, SQLINT4, 1) == FAIL){
MessageBox(NULL, "Error occur when calling bcp_bind!", "Datebase error", MB_OK | MB_ICONSTOP);
return 0;
}
// designate variables for jcsj
if (bcp_bind(dbproc, (BYTE*) &jcsj, 0, (DBINT) -1, (LPCBYTE) NULL, 0, SQLDATETIME, 2) == FAIL){
MessageBox(NULL, "Error occur when calling bcp_bind!", "Datebase error", MB_OK | MB_ICONSTOP);
return 0;
}
// designate variables for hdz, blackness...
if (bcp_bind(dbproc, (BYTE*) &hdz, 0, (DBINT)-1, (LPCBYTE) NULL, 0, SQLFLT4, 3) == FAIL){
MessageBox(NULL, "Error occur when calling bcp_bind!", "Datebase error", MB_OK | MB_ICONSTOP);
return 0;
}
// designate variables for mld, brightness...
if (bcp_bind(dbproc, (BYTE*) &mld, 0, (DBINT)-1, (LPCBYTE) NULL, 0, SQLFLT4, 4) == FAIL){
MessageBox(NULL, "Error occur when calling bcp_bind!", "Datebase error", MB_OK | MB_ICONSTOP);
return 0;
}
// Do not designate variables for tx, image...
if (bcp_bind(dbproc, (BYTE*) NULL, 0, (DBINT) dwImageSize, (LPCBYTE) NULL, 0, SQLIMAGE, 5) == FAIL){
MessageBox(NULL, "Error occur when calling bcp_bind!", "Datebase error", MB_OK | MB_ICONSTOP);
return 0;
}//dbconvert
// designate variables for dealed...
if (bcp_bind(dbproc, (BYTE*) &dealed, 0, (DBINT)-1, (LPCBYTE) NULL, 0, SQLINT4, 6) == FAIL){
MessageBox(NULL, "Error occur when calling bcp_bind!", "Datebase error", MB_OK | MB_ICONSTOP);
return 0;
}
// designate variables for camera_id...
if (bcp_bind(dbproc, (BYTE*) &cameraid, 0, (DBINT)-1, (LPCBYTE) NULL, 0, SQLINT4, 7) == FAIL){
MessageBox(NULL, "Error occur when calling bcp_bind!", "Datebase error", MB_OK | MB_ICONSTOP);
return 0;
}
// transmit date columns...
if(bcp_sendrow(dbproc) == FAIL){
MessageBox(NULL, "Calling bcp_sendrow() error", "Datebase error", MB_OK | MB_ICONSTOP);
return 0;
}
// transmit image...
if(bcp_moretext(dbproc, (DBINT)dwImageSize, (LPCBYTE)lpstrImage) == FAIL){
MessageBox(NULL, "Calling bcp_moretext() error", "Datebase error", MB_OK | MB_ICONSTOP);
return 0;
}
bcp_done(dbproc);
dbclose(dbproc);
dbexit();
return 1;
}
bool CSQLDatebase::DBSetServerName(LPSTR lpstrServerName)
{
HKEY hKey;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -