123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379 |
- #include "StdAfx.h"
- #include "Global.h"
- #include "./helper/ffsco.h"
- #include <sys/types.h>
- #include <sys/stat.h>
- #define BAKDB_FORMAT _T("BACKUP DATABASE [%s] TO DISK='%s' WITH FORMAT")
- TCHAR g_szHostName[MAX_PATH] = {0};
- TCHAR g_ModulePath[MAX_PATH] = _T("");
- TCHAR g_ModuleFileName[MAX_PATH] = _T("");
- TCHAR g_szConnectString[MAX_PATH] = _T("");
- TCHAR g_szDBSource[MAX_PATH] = _T("");
- TCHAR g_szDBSourcePort[MAX_PATH] = _T("");
- DWORD g_dwDBServerPort = 0;
- TCHAR g_szDBAccount[MAX_PATH] = _T("");
- TCHAR g_szDBPassWord[MAX_PATH] = _T("");
- TCHAR g_szDBName[MAX_PATH] = _T("");
- TCHAR g_szLogDBName[MAX_PATH] = _T("");
- DWORD g_dwCSPort = 0;
- TCHAR g_szShareAccount[MAX_PATH] = {0};
- TCHAR g_szSharePasswd[MAX_PATH] = {0};
- TCHAR g_szN8ViewSvrIP[MAX_PATH] = {0};
- TCHAR g_szN8ViewUserDir[MAX_PATH] = {0};
- TCHAR g_szN8ViewStsDir[MAX_PATH] = {0};
- TCHAR g_szN8ViewProductDir[MAX_PATH] = {0};
- TCHAR g_szN8ViewShareDir[MAX_PATH] = {0};
- TCHAR g_szN8ViewShareName[MAX_PATH] = {0};
- BOOL g_bEnableClound = FALSE;
- BOOL g_bExportBarCode = FALSE;
- DWORD g_dwSoftRunTime = 0;
- TCHAR g_szCloundDiskAccount[MAX_PATH] ={0};
- TCHAR g_szCloundDiskPsw[MAX_PATH] = {0};
- DWORD g_dwDBPoolMaxCount = 1;
- DWORD g_dwDBPoolDef = 1;
- BOOL g_bIsCatalogDamage = FALSE;
- BOOL g_bCheckdb = FALSE;
- DWORD g_dwCheckdbTimeOut = 30;
- DWORD g_dwStartDelayTime = 30;
- CStringArray g_AryAllCatalogName;
- #if THE_PRIMARY_GLOBAL_VARIABLE
- int g_TCPport = 5678;
- BOOL g_bReg = 0;
- CString g_strdbpsw;
- CString g_strdbServrename;
- CString g_bakinfo;
- CString g_bakphoto;
- CString g_mainpath;
- SoftKey ytSoftKey;
- CString g_localname;
- CArray<int, int> g_nYearArray;
- CArray<CDatabase*, CDatabase*>g_dbHistoryArray;
- CArray<CDatabase*, CDatabase*>g_branchdbarray;
- CArray<CDatabase*, CDatabase*>g_branchdb2array;
- CStringArray g_branchnamearray;
- CStringArray g_branchname2array;
- CStringArray g_branchiparray;
- CStringArray g_branchdomainarray;
- CDatabase *g_pMaindb = NULL;
- int g_conncount = -1;
- CString g_sdomain;
- CStringArray g_conniparray;
- CStringArray g_connidarray;
- BOOL g_bCheckAll = 0;
- BYTE *g_pSkinData = NULL;
- DWORD g_SkinLeng;
- BOOL g_bAutoRun = 0;
- CStringArray g_filedatearray;
- CStringArray g_filedatearraynew;
- CString g_bakdate;
- CString g_localip;
- BOOL g_bSteal = 0;
- CString g_bakserver1;
- CString g_bakserver2;
- CString g_bakserver3;
- CString g_bakserver4;
- DWORD g_tisks = 0;
- #if 0
- int g_nBakDays = 10;
- int g_nBackupModel = 1;
- #endif
- int g_bAutoCheckSvc = 1;
- HINSTANCE g_hDllInst = NULL;
- HINSTANCE g_Instance = NULL;
- #endif
- bool InitSocketLibrary(IN WORD wVersion)
- {
- WSADATA WSAData = { 0 };
- return ( 0 == WSAStartup( wVersion, &WSAData ) );
- }
- bool ReleaseSocketLibrary()
- {
- return ( 0 == WSACleanup() );
- }
- int GetIniInfo(const TCHAR *szPath, const TCHAR *szIniName)
- {
- TCHAR szDrive[_MAX_DRIVE] = { 0 };
- TCHAR szDir[_MAX_DIR] = { 0 };
- TCHAR szFName[_MAX_FNAME] = { 0 };
- TCHAR szExt[_MAX_EXT] = { 0 };
- ::GetModuleFileName(NULL, g_ModulePath, sizeof(g_ModulePath) / sizeof(TCHAR));
- _stprintf_s(g_ModuleFileName, _T("%s"), g_ModulePath);
- _tsplitpath_s(g_ModulePath, szDrive, szDir, szFName, szExt);
- _tcscpy_s(g_ModulePath, szDrive);
- _tcscat_s(g_ModulePath, szDir);
-
- TCHAR szFile[MAX_PATH + 1] = _T("");
- if (szPath != NULL && szIniName != NULL)
- _stprintf_s(szFile, _T("%s\\%s"), szPath, szIniName);
- else
- _stprintf_s(szFile, _T("%s\\ServiceInfo.ini"), g_ModulePath);
- TRACE("szFile =%s\n", szFile);
- HANDLE hFile = CreateFile(szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
- if (ERROR_FILE_NOT_FOUND == GetLastError())
- {
- return -1;
- }
- CloseHandle(hFile);
- hFile = NULL;
-
- GetPrivateProfileString(_T("DatabaseInfo"), _T("dbSource"), _T(""), g_szDBSource, MAX_PATH, szFile);
- g_dwDBServerPort = GetPrivateProfileInt(_T("DatabaseInfo"), _T("dbServerPort"), 0, szFile);
- GetPrivateProfileString(_T("DatabaseInfo"), _T("dbAccount"), _T(""), g_szDBAccount, MAX_PATH, szFile);
- GetPrivateProfileString(_T("DatabaseInfo"), _T("dbPassWord"), _T(""), g_szDBPassWord, MAX_PATH, szFile);
- GetPrivateProfileString(_T("DatabaseInfo"), _T("dbName"), _T(""), g_szDBName, MAX_PATH, szFile);
- g_dwDBPoolMaxCount = GetPrivateProfileInt(_T("DatabaseInfo"), _T("dbpoolMaxObj"), 50, szFile);
- g_dwDBPoolDef = GetPrivateProfileInt(_T("DatabaseInfo"), _T("dbpoolDef"), 3, szFile);
- #if USE_ADO_OPT_DB
- GetPrivateProfileString("DatabaseInfo", "LogdbName", "", g_szLogDBName, MAX_PATH, szFile);
- #endif
-
- g_dwCSPort = GetPrivateProfileInt(_T("NetWorkInfo"), _T("TCPChatPort"), 5678, szFile);
- if (g_dwDBServerPort != 0)
- {
- if ( _tcscmp(g_szDBAccount, _T("")) == 0 )
- _stprintf_s(g_szConnectString, DB_SW_CONN_WITH_PORT, g_szDBSource, g_dwDBServerPort,g_szDBName);
- else
- _stprintf_s(g_szConnectString, DB_SS_CONN_WITH_PORT,g_szDBSource, g_dwDBServerPort, g_szDBName, g_szDBAccount, g_szDBPassWord);
- }
- else
- {
- if ( _tcscmp(g_szDBAccount, _T("")) == 0 )
- _stprintf_s(g_szConnectString, DB_SW_CONN_WITHOUT_PORT, g_szDBSource, g_szDBName);
- else
- _stprintf_s(g_szConnectString, DB_SS_CONN_WITHOUT_PORT,g_szDBSource, g_szDBName, g_szDBAccount, g_szDBPassWord);
- }
- #if 0
- g_nBakDays = GetPrivateProfileInt("Back", "uBakDays", 10, szFile);
- g_nBackupModel = GetPrivateProfileInt("Back", "uBackupModel", 1, szFile);
- #endif
- g_bAutoCheckSvc = GetPrivateProfileInt("Back", "AutoCheckSvc", 1, szFile);
-
- GetPrivateProfileString(_T("NetWorkInfo"), _T("ShareAccount"), _T(""), g_szShareAccount, MAX_PATH, szFile);
- GetPrivateProfileString(_T("NetWorkInfo"), _T("SharePasswd"), _T(""), g_szSharePasswd, MAX_PATH, szFile);
-
- GetPrivateProfileString(_T("NemoInfo"), _T("N8ViewSvr"), _T(""), g_szN8ViewSvrIP, MAX_PATH, szFile);
- GetPrivateProfileString(_T("NemoInfo"), _T("N8ViewUserDir"), _T(""), g_szN8ViewUserDir, MAX_PATH, szFile);
- GetPrivateProfileString(_T("NemoInfo"), _T("N8ViewStsDir"), _T(""), g_szN8ViewStsDir, MAX_PATH, szFile);
- GetPrivateProfileString(_T("NemoInfo"), _T("N8ViewProductDir"), _T(""), g_szN8ViewProductDir, MAX_PATH, szFile);
- GetPrivateProfileString(_T("NemoInfo"), _T("N8ViewShareDir"), _T(""), g_szN8ViewShareDir, MAX_PATH, szFile);
- GetPrivateProfileString(_T("NemoInfo"), _T("N8ViewShareName"), _T(""), g_szN8ViewShareName, MAX_PATH, szFile);
-
-
- g_bExportBarCode = GetPrivateProfileInt(_T("SystemInfo"), _T("ExportBarCode"), 0, szFile);
- g_bEnableClound = GetPrivateProfileInt(_T("SystemInfo"), _T("EnableClound"), 0, szFile);
-
- GetPrivateProfileString(_T("SystemInfo"), _T("CloundDiskAccount"), _T(""), g_szCloundDiskAccount, MAX_PATH, szFile);
-
- GetPrivateProfileString(_T("SystemInfo"), _T("CloundDiskPsw"), _T(""), g_szCloundDiskPsw, MAX_PATH, szFile);
-
- CString strResult;
- des_crypt((CString)g_szCloundDiskPsw, strResult, DES_DECRYPT);
- _stprintf_s(g_szCloundDiskPsw, MAX_PATH, _T("%s"), strResult.GetString());
-
- g_bCheckdb = GetPrivateProfileInt(_T("SystemInfo"), _T("Checkdb"), 1, szFile);
-
- g_dwCheckdbTimeOut = GetPrivateProfileInt(_T("SystemInfo"), _T("CheckdbTimeOut"), 30, szFile);
- if ( !g_bCheckdb )
- {
- g_bIsCatalogDamage = FALSE;
- }
-
- g_dwStartDelayTime = GetPrivateProfileInt(_T("SystemInfo"), _T("StartDelayTime"), 0, szFile );
- return 0;
- }
- #if THE_PRIMARY_GLOBAL_FUNCTION
- BOOL AddConn(CDatabase *m_conndb, CString dbname)
- {
- try {
- CString strCon;
- strCon.Format(DB_SS_CONN_WITHOUT_PORT, g_strdbServrename, dbname, g_szDBAccount, g_szDBPassWord);
- m_conndb->OpenEx(strCon, CDatabase::noOdbcDialog);
- }
- catch (CDBException * e)
- {
- WriteTextLog(_T("新建连接时出错:%s"),e->m_strError);
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- return 0;
- }
- return 1;
- }
- void WriteError(CString str)
- {
- MyLock lock("DBServerWriteError");
- CStdioFile fp;
- CString path = g_mainpath + "\\MsgError.txt";
- if (::PathFileExists(path))
- {
- fp.Open(path, CFile::modeWrite);
- int length = fp.GetLength();
- if (length > 1024 * 1024)
- {
- fp.Close();
- ::DeleteFile(path);
- return;
- }
- fp.SeekToEnd();
- }
- else
- fp.Open(path, CFile::modeCreate | CFile::modeWrite);
- fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S ") + str + "\n");
- fp.Close();
- }
- void WritePswWrong(CString str)
- {
- MyLock lock("DBServerWritePswWrong");
- CStdioFile fp;
- CString path = g_mainpath + "\\PswWrong.txt";
- if (::PathFileExists(path))
- {
- fp.Open(path, CFile::modeWrite);
- int length = fp.GetLength();
- if (length > 1024 * 1024)
- {
- fp.Close();
- ::DeleteFile(path);
- return;
- }
- fp.SeekToEnd();
- }
- else
- fp.Open(path, CFile::modeCreate | CFile::modeWrite);
- fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S ") + str + "\n");
- fp.Close();
- }
- void WriteNullBalance(CString str)
- {
- MyLock lock("DBServerWriteNullBalance");
- CStdioFile fp;
- CString path = g_mainpath + "\\NullBalance.txt";
- if (::PathFileExists(path))
- {
- fp.Open(path, CFile::modeWrite);
- int length = fp.GetLength();
- if (length > 1024 * 1024)
- {
- fp.Close();
- ::DeleteFile(path);
- return;
- }
- fp.SeekToEnd();
- }
- else
- fp.Open(path, CFile::modeCreate | CFile::modeWrite);
- fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S ") + str + "\n");
- fp.Close();
- }
- void WriteUnallowIP(CString str)
- {
- CStdioFile fp;
- CString path = g_mainpath + "\\UnallowIP.txt";
- if (::PathFileExists(path))
- {
- fp.Open(path, CFile::modeWrite);
- int length = fp.GetLength();
- if (length > 1024 * 1024)
- {
- fp.Close();
- ::DeleteFile(path);
- return;
- }
- fp.SeekToEnd();
- }
- else
- fp.Open(path, CFile::modeCreate | CFile::modeWrite);
- fp.WriteString(CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S ") + str + "\n");
- fp.Close();
- }
- int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
- {
- UINT num = 0;
- UINT size = 0;
- ImageCodecInfo* pImageCodecInfo = NULL;
- GetImageEncodersSize(&num, &size);
- if (size == 0)
- return -1;
- pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
- if (pImageCodecInfo == NULL)
- return -1;
- GetImageEncoders(num, size, pImageCodecInfo);
- for (UINT j = 0; j < num; ++j)
- {
- if (wcscmp(pImageCodecInfo[j].MimeType, format) == 0)
- {
- *pClsid = pImageCodecInfo[j].Clsid;
- free(pImageCodecInfo);
- return j;
- }
- }
- free(pImageCodecInfo);
- return -1;
- }
- void SaveImageToFile(Image *img, CString path)
- {
- try
- {
- if (img == NULL)return;
- CLSID encoderClsid;
- BSTR bstr = path.AllocSysString();
- path.MakeLower();
- if (path.Right(3) == "bmp")
- {
- GetEncoderClsid(L"image/bmp", &encoderClsid);
- img->Save(bstr, &encoderClsid, NULL);
- }
- else if (path.Right(3) == "png")
- {
- GetEncoderClsid(L"image/png", &encoderClsid);
- img->Save(bstr, &encoderClsid, NULL);
- }
- else
- {
- GetEncoderClsid(L"image/jpeg", &encoderClsid);
- EncoderParameters encoderParameters;
- ULONG quality;
- encoderParameters.Count = 1;
- encoderParameters.Parameter[0].Guid = EncoderQuality;
- encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
- encoderParameters.Parameter[0].NumberOfValues = 1;
-
- quality = 100;
- encoderParameters.Parameter[0].Value = &quality;
- img->Save(bstr, &encoderClsid, &encoderParameters);
- }
- SysFreeString(bstr);
- }
- catch (...)
- {
- }
- }
- void SaveImageToFile2(Image *img, CString path, ULONG quality)
- {
- try
- {
- if (img == NULL)return;
- CLSID encoderClsid;
- BSTR bstr = path.AllocSysString();
- path.MakeLower();
- if (path.Right(3) == "bmp")
- {
- GetEncoderClsid(L"image/bmp", &encoderClsid);
- img->Save(bstr, &encoderClsid, NULL);
- }
- else if (path.Right(3) == "png")
- {
- GetEncoderClsid(L"image/png", &encoderClsid);
- img->Save(bstr, &encoderClsid, NULL);
- }
- else
- {
- GetEncoderClsid(L"image/jpeg", &encoderClsid);
- EncoderParameters encoderParameters;
- encoderParameters.Count = 1;
- encoderParameters.Parameter[0].Guid = EncoderQuality;
- encoderParameters.Parameter[0].Type = EncoderParameterValueTypeLong;
- encoderParameters.Parameter[0].NumberOfValues = 1;
-
- encoderParameters.Parameter[0].Value = &quality;
- img->Save(bstr, &encoderClsid, &encoderParameters);
- }
- SysFreeString(bstr);
- }
- catch (...)
- {
- }
- }
- void RectFitDes(int width, int height, CRect &rc)
- {
- float fscale = (float)width / (float)height;
- float rcscale = ((float)rc.Width()) / ((float)rc.Height());
- int rcwid = rc.Width();
- int rchei = rc.Height();
- int dt = 0;
- if (rcscale < fscale)
- {
- dt = (rchei - rcwid / fscale) / 2;
- rc.top += dt;
- rc.bottom -= dt;
- }
- else
- {
- dt = (rcwid - rchei*fscale) / 2;
- rc.left += dt;
- rc.right -= dt;
- }
- }
- bool CheckFolderFileExist(CString &strPath)
- {
- strPath.MakeLower();
-
- if(!PathFileExists(strPath))
- return 0;
- CString path = strPath;
- CFile fp;
- if (fp.Open(path, CFile::modeRead))
- {
- fp.Close();
- return 1;
- }
- if (strPath.Right(1) != "\\")
- path += "\\";
- path += "zaqw1234.dat";
- ::DeleteFile(path);
- if (fp.Open(path, CFile::modeCreate) == 0)
- return 0;
- fp.Close();
- ::DeleteFile(path);
- return 1;
- }
- bool CheckFileExist(CString &strPath)
- {
- strPath.MakeLower();
- if (strPath.Find("c:\\") != -1 || strPath.Find("d:\\") != -1 || strPath.Find("e:\\") != -1 || strPath.Find("f:\\") != -1 || strPath.Find("g:\\") != -1 || strPath.Find("h:\\") != -1 || strPath.Find("i:\\") != -1 || strPath.Find("j:\\") != -1 || strPath.Find("k:\\") != -1 || strPath.Find("l:\\") != -1 || strPath.Find("m:\\") != -1)
- {
- return ::PathFileExists(strPath);
- }
- CString path = strPath;
- CFile fp;
- if (fp.Open(path, CFile::modeRead))
- {
- fp.Close();
- return 1;
- }
- return 0;
- }
- BOOL EncryptFile2(BYTE *buffer, DWORD leng, PCHAR szPassword)
- {
- try
- {
- HCRYPTPROV hCryptProv;
- HCRYPTKEY hKey;
- HCRYPTHASH hHash;
- PBYTE pbBuffer;
- DWORD dwBlockLen;
- DWORD dwBufferLen;
- DWORD dwCount;
-
- if (CryptAcquireContext(
- &hCryptProv,
- NULL,
- NULL,
- PROV_RSA_FULL,
- 0))
- {
- printf("A cryptographic provider has been acquired. \n");
- }
- else
- {
- if (CryptAcquireContext(
- &hCryptProv,
- NULL,
- NULL,
- PROV_RSA_FULL,
- CRYPT_NEWKEYSET))
- {
-
- printf("A new key container has been created.\n");
- }
- else
- {
- return 0;
- }
- }
-
-
-
-
-
-
-
- if (CryptCreateHash(
- hCryptProv,
- CALG_MD5,
- 0,
- 0,
- &hHash))
- {
- printf("A hash object has been created. \n");
- }
- else
- {
- return 0;
- }
-
-
- if (CryptHashData(
- hHash,
- (BYTE *)szPassword,
- strlen(szPassword),
- 0))
- {
- printf("The password has been added to the hash. \n");
- }
- else
- {
- return 0;
- }
-
-
- if (CryptDeriveKey(
- hCryptProv,
- ENCRYPT_ALGORITHM,
- hHash,
- KEYLENGTH,
- &hKey))
- {
- printf("An encryption key is derived from the password hash. \n");
- }
- else
- {
- return 0;
- }
-
-
- CryptDestroyHash(hHash);
- hHash = NULL;
-
-
-
-
-
-
- dwBlockLen = 1000 - 1000 % ENCRYPT_BLOCK_SIZE;
-
-
-
- if (ENCRYPT_BLOCK_SIZE > 1)
- dwBufferLen = dwBlockLen + ENCRYPT_BLOCK_SIZE;
- else
- dwBufferLen = dwBlockLen;
- dwCount = dwBufferLen;
-
-
- int count;
-
- count = leng / dwBufferLen;
-
-
- int i = 0;
- for (i = 0; i < count; i++)
- {
- pbBuffer = buffer + i*dwBufferLen;
-
- if (!CryptEncrypt(
- hKey,
- 0,
- 0,
-
- 0,
- pbBuffer,
- &dwCount,
- dwBufferLen))
- {
- return 0;
- }
- }
- if (leng%dwBlockLen)
- {
- pbBuffer = buffer + i*dwBufferLen;
- dwCount = leng - i*dwBufferLen;
- if (!CryptEncrypt(
- hKey,
- 0,
- TRUE,
-
- 0,
- pbBuffer,
- &dwCount,
- dwBufferLen))
- {
- return 0;
- }
- }
-
-
- if (hKey)
- CryptDestroyKey(hKey);
-
-
- if (hHash)
- CryptDestroyHash(hHash);
-
-
- if (hCryptProv)
- CryptReleaseContext(hCryptProv, 0);
- return(TRUE);
- }
- catch (...)
- {
- }
- }
- void BackupDatabase( IN CString strBackupDir, IN BOOL bBackupToday, IN BOOL bBackupHistory )
- {
-
- CDatabase tagMaster;
- 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);
- }
- tagMaster.OpenEx(szConnectString, CDatabase::noOdbcDialog);
- }
- catch (CDBException *e)
- {
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- }
- try
- {
-
- CTime tToday = CTime::GetCurrentTime();
- CTimeSpan tSpan(1, 0, 0, 0);
- CTime tYesterday;
- if (bBackupToday)
- tYesterday = tToday;
- else
- tYesterday = tToday - tSpan;
- CString savepath;
- savepath.Format(_T("%s\\%s(sql).bak"), strBackupDir, tYesterday.Format(_T("%Y%m%d")));
- BOOL bBak = 0;
- BOOL bBak2 = 0;
-
- if (!PathFileExists(savepath))
- {
- tagMaster.SetQueryTimeout(600);
- {
- CString sql;
- sql.Format(_T("BACKUP DATABASE [%s] TO DISK='%s' WITH FORMAT"), g_szDBName, savepath);
- try
- {
- tagMaster.ExecuteSQL(sql);
- bBak = 1;
- g_bakinfo = _T("资料备份成功");
- }
- catch (CDBException * e)
- {
- #ifdef _DEBUG
- e->ReportError();
- #endif
- WriteTextLog(_T("备份失败:%s"),e->m_strError);
- e->Delete();
- }
- }
- tagMaster.SetQueryTimeout(100);
- }
-
- if (bBackupHistory)
- {
- for (int i = CTime::GetCurrentTime().GetYear() - 1; i >= 2009; i--)
- {
- tagMaster.SetQueryTimeout(600);
- {
- CString savepath2;
- savepath2.Format(_T("%s\\%s-%d(sql).bak"), strBackupDir, tYesterday.Format(_T("%Y%m%d")), i);
- CString sql;
- sql.Format(_T("BACKUP DATABASE [%d] TO DISK='%s' WITH FORMAT"), i, savepath2);
- try
- {
- tagMaster.ExecuteSQL(sql);
- bBak2 = 1;
- }
- catch (CDBException * e)
- {
- #ifdef _DEBUG
- e->ReportError();
- #endif
- e->Delete();
- break;
- }
- }
- tagMaster.SetQueryTimeout(100);
- }
- }
-
- if (bBak)
- {
- CTimeSpan dt2(31, 0, 0, 0);
- CTimeSpan dt3(365, 0, 0, 0);
-
- CTime tm3 = tToday - dt2;
- CTime tm4 = tToday - dt3;
-
- while (tm3 > tm4)
- {
- savepath.Format(_T("%s\\%s.bak"), strBackupDir, tm3.Format(_T("%Y%m%d")));
- #ifdef SQLSERVER_VERSION
- savepath.Format(_T("%s\\%s(sql).bak"), strBackupDir, tm3.Format(_T("%Y%m%d")));
- #endif
-
- if (!CheckFileExist(savepath))
- break;
- ::DeleteFile(savepath);
- tm3 -= tSpan;
- }
- }
- if (bBak2)
- {
- CTimeSpan dt2(15, 0, 0, 0);
- CTimeSpan dt3(365, 0, 0, 0);
- for (int i = tToday.GetYear() - 1; i >= 2009; i--)
- {
- CTime tm3 = tToday - dt2;
- CTime tm4 = tToday - dt3;
- while (tm3 > tm4)
- {
- savepath.Format(_T("%s\\%s-%d.bak"), strBackupDir, tm3.Format(_T("%Y%m%d")), i);
- #ifdef SQLSERVER_VERSION
- savepath.Format(_T("%s\\%s-%d(sql).bak"), strBackupDir, tm3.Format(_T("%Y%m%d")), i);
- #endif
- if (!CheckFileExist(savepath))
- break;
- ::DeleteFile(savepath);
- tm3 -= tSpan;
- }
- }
- }
- }
- catch (...)
- {
- WriteTextLog("出错在函数BackupDatabase中");
- }
- tagMaster.Close();
- }
- void BakData(CString savedir, BOOL bToday, BOOL bBakHis)
- {
- #ifdef SQLSERVER_VERSION
- BackupDatabase(savedir, bToday, bBakHis);
- return;
- #endif
- try
- {
- CTime tm = CTime::GetCurrentTime();
- CTimeSpan dt(1, 0, 0, 0);
- CTime tm2;
- if (bToday)
- tm2 = tm;
- else
- tm2 = tm - dt;
- CString savepath;
- savepath.Format("%s\\%s.bak", savedir, tm2.Format("%Y%m%d"));
- #ifdef SQLSERVER_VERSION
- savepath.Format("%s\\%s(sql).bak", savedir, tm2.Format("%Y%m%d"));
- #endif
- BOOL bBak = 0;
- BOOL bBak2 = 0;
- {
- TCHAR szDBFile[MAX_PATH] = _T("");
- #ifdef SQLSERVER_VERSION
- _stprintf_s(szDBFile, _T("%s\\数据\\%s.mdf"), g_ModulePath, g_szDBName);
-
- #else
- sprintf(szDBFile, "%s\\数据\\%s.mdb", g_ModulePath, g_szDBName);
-
- #endif
- if (::CopyFile(szDBFile, savepath, 0))
- {
- bBak = 1;
- g_bakinfo = "资料备份成功";
- }
- }
- if (bBak)
- {
- CTimeSpan dt2(15, 0, 0, 0);
- CTimeSpan dt3(365, 0, 0, 0);
- CTime tm3 = tm - dt2;
- CTime tm4 = tm - dt3;
- while (tm3 > tm4)
- {
- savepath.Format("%s\\%s.bak", savedir, tm3.Format("%Y%m%d"));
- #ifdef SQLSERVER_VERSION
- savepath.Format("%s\\%s(sql).bak", savedir, tm3.Format("%Y%m%d"));
- #endif
- if (!CheckFileExist(savepath))
- break;
- ::DeleteFile(savepath);
- tm3 -= dt;
- }
- }
-
- for (int i = tm.GetYear() - 1; i >= 1900; i--)
- {
- #ifdef SQLSERVER_VERSION
- savepath.Format("%s\\数据\\%d.mdf", g_mainpath, i);
- #else
- savepath.Format("%s\\数据\\%d.mdb", g_mainpath, i);
- #endif
- if (CheckFileExist(savepath) == 0)
- break;
- CString savepath2 = _T("");
- savepath2.Format("%s\\%s-%d.bak", savedir, tm2.Format("%Y%m%d"), i);
- #ifdef SQLSERVER_VERSION
- savepath2.Format("%s\\%s-%d(sql).bak", savedir, tm2.Format("%Y%m%d"), i);
- #endif
- if (::CopyFile(savepath, savepath2, 0))
- bBak2 = 1;
- }
- if (bBak2)
- {
- CTimeSpan dt2(7, 0, 0, 0);
- CTimeSpan dt3(365, 0, 0, 0);
- for (int i = tm.GetYear() - 1; i >= 1900; i--)
- {
- #ifdef SQLSERVER_VERSION
- savepath.Format("%s\\数据\\%d.mdf", g_mainpath, i);
- #else
- savepath.Format("%s\\数据\\%d.mdb", g_mainpath, i);
- #endif
- if (CheckFileExist(savepath) == 0)break;
- CTime tm3 = tm - dt2;
- CTime tm4 = tm - dt3;
- while (tm3 > tm4)
- {
- savepath.Format("%s\\%s-%d.bak", savedir, tm3.Format("%Y%m%d"), i);
- #ifdef SQLSERVER_VERSION
- savepath.Format("%s\\%s-%d(sql).bak", savedir, tm3.Format("%Y%m%d"), i);
- #endif
- if (!CheckFileExist(savepath))
- break;
- ::DeleteFile(savepath);
- tm3 -= dt;
- }
- }
- }
- }
- catch (...)
- {
- WriteTextLog("出错在函数BakData中");
- }
- }
- DWORD FindAppProcessID(CString path)
- {
- try
- {
- HANDLE handle = ::CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
- PROCESSENTRY32 Info;
- Info.dwSize = sizeof(PROCESSENTRY32);
- path.MakeLower();
- if (::Process32First(handle, &Info))
- {
- do
- {
- CString ss = Info.szExeFile;
- ss.MakeLower();
- if (ss == path)
- {
- ::CloseHandle(handle);
- return Info.th32ProcessID;
- }
- } while (::Process32Next(handle, &Info));
- ::CloseHandle(handle);
- }
- return 0;
- }
- catch (...)
- {
- }
- return 0;
- }
- BOOL lyfzCopyFileEx(LPCTSTR lpExistingFileName, LPCTSTR lpNewFileName, const BOOL &bFailIfExists)
- {
-
- if (!bFailIfExists)
- return CopyFile(lpExistingFileName, lpNewFileName, bFailIfExists);
-
- TCHAR szNewFileName[1024] = { 0 };
- TCHAR szDrive[_MAX_DRIVE] = { 0 };
- TCHAR szDir[_MAX_DIR] = { 0 };
- TCHAR szFna[_MAX_FNAME] = { 0 };
- TCHAR szExt[_MAX_EXT] = { 0 };
- _stprintf_s(szNewFileName, _T("%s"), lpNewFileName);
- _tsplitpath_s(szNewFileName, szDrive, szDir, szFna, szExt);
- int nIndex = 1;
- while (PathFileExists(szNewFileName))
- {
- _stprintf_s(szNewFileName, _T("%s%s%s (%d)%s"), szDrive, szDir, szFna, nIndex++, szExt);
- }
- return CopyFile(lpExistingFileName, szNewFileName, bFailIfExists);
- }
- void GetPathFromNetShareName(CString name, CString &sRet)
- {
- if (sRet.Find(":") != -1)return;
- NET_API_STATUS res;
- SHARE_INFO_502 * psi = NULL;
- WCHAR wszShareName[255];
- TCHAR szPathName[255];
- TCHAR path[255];
- memset(path, 0, 255);
-
- MultiByteToWideChar(CP_ACP, 0, name, -1, wszShareName, 255);
- #if 0
- res = NetShareGetInfo(NULL, (char *)wszShareName, 502, (LPBYTE *)&psi);
- #else
- res = NetShareGetInfo(NULL, wszShareName, 502, (LPBYTE *)&psi);
- #endif
- if (res == NERR_Success)
- {
- wsprintf((char*)szPathName, "%S ", psi->shi502_path);
- sRet = szPathName;
- sRet.TrimRight();
- }
- else
- {
- CString str;
- #if 0
- str.Format("转换路径失败-%d", res);
- ::WriteTextLog(str);
- #else
- str.Format("转换路径失败(\"%s\"),", sRet);
- ErrorExit(str, res);
- #endif
- }
-
- NetApiBufferFree(psi);
- }
- CString GetModifyTime2(CString path)
- {
- try
- {
- CFileFind finder;
- BOOL bWorking = finder.FindFile(path);
- if (bWorking)
- {
- finder.FindNextFile();
- CTime tm;
- finder.GetLastWriteTime(tm);
- CString stime;
- stime.Format("%d%02d%02d", tm.GetYear(), tm.GetMonth(), tm.GetDay());
- return stime;
- }
- return "";
- }
- catch (CFileException *e)
- {
- WriteTextLog(_T("2.读文件[%s]修改时间出错:%d"), e->m_strFileName, e->m_lOsError);
- e->Delete();
- }
- return _T("");
- }
- CString GetModifyTime(CString path)
- {
- try
- {
- HANDLE hFile;
- WIN32_FIND_DATA wfd;
-
- FILETIME localtime;
- CString stime;
- memset(&wfd, 0, sizeof(wfd));
- if ((hFile = FindFirstFile(path, &wfd)) == INVALID_HANDLE_VALUE)
- return "";
-
- FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localtime);
- stime.Format("%16d%16d", localtime.dwHighDateTime, localtime.dwLowDateTime);
- return stime;
- }
- catch (CFileException *e)
- {
- CString strError;
- WriteTextLog(_T("读文件[%s]修改时间出错:%d"), e->m_strFileName, e->m_lOsError);
- e->Delete();
- }
- return _T("");
- }
- CString GetErrorInfo(IN const DWORD &dwError)
- {
- LPVOID lpMsgBuf;
- CString strErrorInfo;
- BOOL fOk = FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER |FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- dwError,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR)&lpMsgBuf,
- 0, NULL
- );
- if (!fOk)
- {
-
- HMODULE hDll = LoadLibraryEx(TEXT("netmsg.dll"), NULL, DONT_RESOLVE_DLL_REFERENCES);
- if (hDll != NULL)
- {
- FormatMessage(
- FORMAT_MESSAGE_FROM_HMODULE |FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_IGNORE_INSERTS,
- hDll, dwError,
- MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
- (LPTSTR)&lpMsgBuf,
- 0, NULL
- );
- FreeLibrary(hDll);
- }
- }
- if (lpMsgBuf != NULL)
- {
- strErrorInfo.Format(_T("错误码=%d,系统描述:%s"), dwError, (PCTSTR)LocalLock(lpMsgBuf));
- LocalFree(lpMsgBuf);
- }
- else
- {
- strErrorInfo.Format(_T("错误码=%d,系统描述:未知错误内容!"), dwError);
- }
- return strErrorInfo;
- }
- void ErrorExit(CString strDescription, const DWORD &dwError)
- {
- #if 1
- LPVOID lpMsgBuf;
- BOOL fOk = FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- dwError,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR)&lpMsgBuf,
- 0, NULL);
- if (!fOk)
- {
-
- HMODULE hDll = LoadLibraryEx(TEXT("netmsg.dll"), NULL, DONT_RESOLVE_DLL_REFERENCES);
- if (hDll != NULL)
- {
- FormatMessage(
- FORMAT_MESSAGE_FROM_HMODULE |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- hDll,
- dwError,
- MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
- (LPTSTR)&lpMsgBuf,
- 0,
- NULL);
- FreeLibrary(hDll);
- }
- }
- if (lpMsgBuf != NULL)
- {
- WriteTextLog("%s.错误码=%d,Windows描述:%s", strDescription, dwError, (LPCTSTR)LocalLock(lpMsgBuf));
- LocalFree(lpMsgBuf);
- }
- else
- {
- WriteTextLog(strDescription);
- }
- #else
- HLOCAL hlocal = NULL;
-
- BOOL fOk = FormatMessage(
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL,
- dwError,
- MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
- (PTSTR)&hlocal,
- 0,
- NULL);
- if (!fOk)
- {
-
- HMODULE hDll = LoadLibraryEx(TEXT("netmsg.dll"), NULL, DONT_RESOLVE_DLL_REFERENCES);
- if (hDll != NULL)
- {
- FormatMessage(
- FORMAT_MESSAGE_FROM_HMODULE |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- hDll,
- dwError,
- MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
- (PTSTR)&hlocal,
- 0,
- NULL);
- FreeLibrary(hDll);
- }
- }
- if (hlocal != NULL)
- {
- CString strDisplay;
- strDisplay.Format("%s 失败错误码=%d,Windows系统描述:%s", strDescription, dwError, (PCTSTR)LocalLock(hlocal));
- WriteTextLog(strDisplay);
- LocalFree(hlocal);
- }
- else
- {
- WriteTextLog("Error number not found.");
- }
- #endif
- }
- void MyGetIPByName(CString &name)
- {
- CString strIP = name;
- name.Empty();
- DWORD dwServerIP = 0;
- HOSTENT *host = gethostbyname(strIP);
- struct in_addr addr;
- if (host != NULL)
- {
- for (int i = 0; host->h_addr_list[i] != NULL; i++)
- {
- memset(&addr, 0, sizeof(addr));
- memcpy(&addr.S_un.S_addr, host->h_addr_list[i], host->h_length);
- dwServerIP = ntohl(addr.S_un.S_addr);
- }
- BYTE* pIP = (BYTE*)&dwServerIP;
- name.Format(_T("%d.%d.%d.%d"), pIP[3], pIP[2], pIP[1], pIP[0]);
- }
- }
- void EncryptFile3(CString path)
- {
- CFile fp;
- if (fp.Open(path, CFile::modeRead) == 0)return;
- DWORD leng = fp.GetLength();
- BYTE *pData = new BYTE[leng];
- fp.Read(pData, leng);
- fp.Close();
- EncryptFile2(pData, leng, "z9871234abcd");
- fp.Open(path, CFile::modeWrite);
- fp.Write(pData, leng);
- fp.Close();
- delete[]pData;
- }
- int FindArray(CStringArray *pArray, CString Str)
- {
- for (int i = 0; i < pArray->GetSize(); i++)
- {
- if (pArray->ElementAt(i) == Str)
- return i;
- }
- return -1;
- }
- BOOL isInnerIP(DWORD a_ip)
- {
- BOOL bValid = 0;
- if ((a_ip >> 24 == 0xa) || (a_ip >> 16 == 0xc0a8) || (a_ip >> 22 == 0x2b0))
- {
- bValid = 1;
- }
- return bValid;
- }
- BOOL CompareIP(CString name1, CString name2)
- {
- CStringArray g_serverarray1;
- CStringArray g_serverarray2;
- CString strIP = name1;
- DWORD dwServerIP = 0;
- HOSTENT *host = gethostbyname(strIP);
- struct in_addr addr;
- if (host != NULL)
- {
- for (int i = 0; host->h_addr_list[i] != NULL; i++)
- {
- memset(&addr, 0, sizeof(addr));
- memcpy(&addr.S_un.S_addr, host->h_addr_list[i], host->h_length);
- dwServerIP = ntohl(addr.S_un.S_addr);
- BYTE* pIP = (BYTE*)&dwServerIP;
- strIP.Format(_T("%d.%d.%d.%d"), pIP[3], pIP[2], pIP[1], pIP[0]);
- g_serverarray1.Add(strIP);
- }
- }
- while (g_serverarray1.GetSize() > 1)
- {
- CString name;
- BOOL bFind = 0;
- for (int i = 0; i < g_serverarray1.GetSize(); i++)
- {
- DWORD dwServerIP = inet_addr(g_serverarray1.ElementAt(i));
- dwServerIP = htonl(dwServerIP);
- if (isInnerIP(dwServerIP) == 0)
- {
- g_serverarray1.RemoveAt(i);
- bFind = 1;
- break;
- }
- }
- if (bFind == 0)
- {
- break;
- }
- }
-
- {
- CString strIP = name2;
- DWORD dwServerIP = 0;
- HOSTENT *host = gethostbyname(strIP);
- struct in_addr addr;
- if (host != NULL)
- {
- for (int i = 0; host->h_addr_list[i] != NULL; i++)
- {
- memset(&addr, 0, sizeof(addr));
- memcpy(&addr.S_un.S_addr, host->h_addr_list[i], host->h_length);
- dwServerIP = ntohl(addr.S_un.S_addr);
- BYTE* pIP = (BYTE*)&dwServerIP;
- strIP.Format(_T("%d.%d.%d.%d"), pIP[3], pIP[2], pIP[1], pIP[0]);
- g_serverarray2.Add(strIP);
- }
- }
- while (g_serverarray2.GetSize() > 1)
- {
- CString name;
- BOOL bFind = 0;
- for (int i = 0; i < g_serverarray2.GetSize(); i++)
- {
- DWORD dwServerIP = inet_addr(g_serverarray2.ElementAt(i));
- dwServerIP = htonl(dwServerIP);
- if (isInnerIP(dwServerIP) == 0)
- {
- g_serverarray2.RemoveAt(i);
- bFind = 1;
- break;
- }
- }
- if (bFind == 0)
- {
- break;
- }
- }
- }
- if (g_serverarray1.GetSize() == 0 || g_serverarray2.GetSize() == 0)return 1;
- for (int i = 0; i < g_serverarray1.GetSize(); i++)
- {
- for (int j = 0; j < g_serverarray2.GetSize(); j++)
- {
- if (g_serverarray1.ElementAt(i) == g_serverarray2.ElementAt(j))return 0;
- }
- }
- return 1;
- }
- void DeleteDirectory(CString strDir)
- {
- if ( strDir.IsEmpty() || !PathFileExists(strDir) )
- {
- WriteTextLog(_T("DeleteDirectory:路径无效!"));
- return;
- }
- try
- {
-
- CFileFind ff;
- BOOL bFound = ff.FindFile(strDir + _T("\\*"), 0);
- while (bFound)
- {
- bFound = ff.FindNextFile();
- if (ff.GetFileName() == _T(".") || ff.GetFileName() == _T(".."))
- continue;
-
- if ( SetFileAttributes(ff.GetFilePath(), FILE_ATTRIBUTE_NORMAL) )
- {
- if (ff.IsDirectory())
- {
- DeleteDirectory(ff.GetFilePath());
- RemoveDirectory(ff.GetFilePath());
- }
- else
- {
- DeleteFile(ff.GetFilePath());
- WriteTextLog(ff.GetFilePath());
- }
- }
- else
- {
- WriteTextLog(_T("设置文件[%s]属性失败:%d"), ff.GetFilePath(), GetLastError());
- }
- }
- ff.Close();
-
- RemoveDirectory(strDir);
- }
- catch (...)
- {
- WriteTextLog(_T("出错在函数deldir中"));
- }
- }
- int GetLengthEx(CString str)
- {
- wchar_t wstr[500];
- int k = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, strlen(str), wstr, 500);
- return k;
- }
- CString GetFileSize(CString path)
- {
- CString str = "0";
- try
- {
- CFile fp;
- fp.Open(path, CFile::modeRead);
- str.Format("%d", fp.GetLength());
- fp.Close();
- }
- catch (...)
- {
- }
- return str;
- }
- void SortArray(CStringArray &datearray)
- {
- try
- {
- CString strtemp;
- int last = datearray.GetSize() - 1;
- bool sorted = true;
- do {
- sorted = true;
- for (int i = 0; i < last; i++)
- {
- if (datearray[i] < datearray[i + 1])
- {
- strtemp = datearray[i];
- datearray[i] = datearray[i + 1];
- datearray[i + 1] = strtemp;
- sorted = false;
- }
- }
- last--;
- } while (!sorted);
- }
- catch (...)
- {
- WriteTextLog("SortArray出错");
- }
- }
- int CheckPhoneType(CString phoneno)
- {
- if (phoneno.IsEmpty())return -1;
- int i = 0;
- for (i = 0; i < phoneno.GetLength(); i++)
- {
- if (phoneno.GetAt(i) < '0' || phoneno.GetAt(i) > '9')return -1;
- }
- if (phoneno.GetAt(0) == '1')
- {
- if (phoneno.GetLength() != 11)
- return -1;
- int mobile[] = { 139, 138, 137, 136, 135, 134, 159, 158, 152, 151, 150, 157, 188, 187, 144, 182, 147, 183, 184 };
- int unicom[] = { 130, 131, 132, 155, 156, 186, 185 };
- int telecom[] = { 133, 153, 189, 180, 181 };
- for (i = 0; i < sizeof(mobile) / sizeof(int); i++)
- {
- if (mobile[i] == atoi(phoneno.Left(3)))
- {
- return 0;
- }
- }
- for (i = 0; i < sizeof(unicom) / sizeof(int); i++)
- {
- if (unicom[i] == atoi(phoneno.Left(3)))
- {
- return 1;
- }
- }
- for (i = 0; i < sizeof(telecom) / sizeof(int); i++)
- {
- if (telecom[i] == atoi(phoneno.Left(3)))
- {
- return 2;
- }
- }
- return -1;
- }
-
- return -1;
- }
- CTime GetTmFromStr(CString date)
- {
- try
- {
- CTime tm(atoi(date.Mid(0, 4)), atoi(date.Mid(5, 2)), atoi(date.Mid(8, 2)), 0, 0, 0);
- CString ss;
- ss.Format("%d-%d-%d", tm.GetYear(), tm.GetMonth(), tm.GetDay());
- return tm;
- }
- catch (...)
- {
- date = "1980-01-01";
- CTime tm(atoi(date.Mid(0, 4)), atoi(date.Mid(5, 2)), atoi(date.Mid(8, 2)), 0, 0, 0);
- return tm;
- }
- }
- void ConvertToPrice(CString &str)
- {
- if (str.Find('.') == -1)return;
- str.TrimRight('0');
- str.TrimRight('.');
- }
- void SortArray(CArray<CStringArray, CStringArray>*List1array, int pos)
- {
- CString stemp;
- int last = List1array->GetSize() - 1;
- int ret = last;
- bool sorted = true;
- do
- {
- sorted = true;
- for (int i = 0; i < last; i++)
- {
- if (List1array->ElementAt(i).ElementAt(pos) < List1array->ElementAt(i + 1).ElementAt(pos))
- {
- for (int a = 0; a < List1array->ElementAt(i).GetSize(); a++)
- {
- stemp = List1array->ElementAt(i).ElementAt(a);
- List1array->ElementAt(i).SetAt(a, List1array->ElementAt(i + 1).ElementAt(a));
- List1array->ElementAt(i + 1).SetAt(a, stemp);
- }
- sorted = false;
- }
- }
- last--;
- } while (!sorted);
- }
- void DeCodePicCount(int &value1, int &value2)
- {
-
- int ret = 0;
- if (ret != 0)
- {
- return;
- }
- int d[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("");
-
- ret = ytSoftKey.decryptpiccount(&value1, &value2, &d[2], &d[3], &d[4], &d[5], &d[6], &d[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)
- {
- exit(0);
- }
- }
- void DeCodelong1(int &value1, int &value2, int &value3, int &value4, int &value5, int &value6, int &value7, int &value8)
- {
-
- int ret = 0;
- if (ret != 0)
- {
- return;
- }
- 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("");
-
- ret = ytSoftKey.decryptlong1(&value1, &value2, &value3, &value4, &value5, &value6, &value7, &value8,
- &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)
- {
- exit(0);
- }
- }
- void DeCodelong2(int &value1, int &value2, int &value3, int &value4, int &value5, int &value6, int &value7, int &value8)
- {
-
- int ret = 0;
- if (ret != 0)
- {
- return;
- }
- 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("");
-
- ret = ytSoftKey.decryptlong2(&value1, &value2, &value3, &value4, &value5, &value6, &value7, &value8,
- &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)
- {
- exit(0);
- }
- }
- void DeCodelong3(int &value1, int &value2, int &value3, int &value4, int &value5, int &value6, int &value7, int &value8)
- {
-
- int ret = 0;
- if (ret != 0)
- {
- return;
- }
- 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("");
-
- ret = ytSoftKey.decryptlong3(&value1, &value2, &value3, &value4, &value5, &value6, &value7, &value8,
- &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)
- {
- exit(0);
- }
- }
- void DeCodelong4(int &value1, int &value2, int &value3, int &value4, int &value5, int &value6, int &value7, int &value8)
- {
-
- int ret = 0;
- if (ret != 0)
- {
- exit(0);
- }
- 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("");
-
- ret = ytSoftKey.decryptlong4(&value1, &value2, &value3, &value4, &value5, &value6, &value7, &value8,
- &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)
- {
- exit(0);
- }
- }
- #endif
- #if JEFF_TEST_ON
- BOOL IsValidDate(IN LPCTSTR lpDate)
- {
- if (lpDate == NULL || _tcscmp(lpDate, _T("")) == 0)
- return FALSE;
- CString strDate = lpDate;
- if (strDate.IsEmpty()) return FALSE;
-
- static int nYear = 0;
- static int nMonth = 0;
- static int nDay = 0;
- nYear = nMonth = nDay = 0;
- nYear = _ttoi(strDate.Left(4));
- nMonth = _ttoi(strDate.Mid(5, 2));
- nDay = _ttoi(strDate.Mid(8, 2));
- CONST static INT nNormalMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- CONST static INT nLeapMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- if ((nDay <= 0) || (nDay > 31) || (nMonth <= 0) || (nMonth > 12)) return FALSE;
- if ((nYear % 400 == 0) || (nYear % 4 == 0 && nYear % 100 != 0))
- {
- if (nDay > nLeapMonth[nMonth - 1]) return FALSE;
- }
- else
- {
- if (nDay > nNormalMonth[nMonth - 1]) return FALSE;
- }
- return TRUE;
- }
- #endif
- int LoadBackupModuleDll(IN CONST CString strDll)
- {
- if (!::PathFileExists(strDll))
- return 0;
- HRESULT hr = NULL;
- if(g_hDllInst)
- return 1;
- if(g_hDllInst == NULL)
- {
- g_hDllInst = LoadLibrary(strDll);
- if(g_hDllInst == NULL)
- {
- WriteTextLog(_T("加载") + strDll + _T("失败\n"));
- return 0;
- }
- }
- WriteTextLog(_T("加载") + strDll + _T("成功\n"));
- return 1;
- }
- void FreeBackupModuleDll()
- {
- if(g_hDllInst != NULL)
- FreeLibrary(g_hDllInst);
- g_hDllInst = NULL;
- }
- static INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData)
- {
- switch (uMsg)
- {
- case BFFM_INITIALIZED:
- SendMessage(hwnd, BFFM_SETSELECTION, TRUE, NULL);
- break;
- case BFFM_SELCHANGED:
- {
- TCHAR szFileName[MAX_PATH];
- LPITEMIDLIST pidlCurrent = (LPITEMIDLIST)lp;
- SHGetPathFromIDList(pidlCurrent, szFileName);
- SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szFileName);
- }
- break;
-
-
-
-
-
-
-
-
-
-
- }
- return 0;
- }
- BOOL GetFilePath(OUT TCHAR *FilePath, IN HWND hParentWnd, IN TCHAR* InstructionString, IN UINT ulFlags)
- {
- BROWSEINFO bInfo;
- LPITEMIDLIST pidl, pidlDesktop;
- ZeroMemory((PVOID)&bInfo, sizeof(BROWSEINFO));
- HRESULT hr = SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidlDesktop);
- if ( hr != S_OK )
- {
-
- return FALSE;
- }
- bInfo.pidlRoot = pidlDesktop;
- bInfo.hwndOwner = hParentWnd;
- bInfo.pszDisplayName = FilePath;
- bInfo.lpszTitle = InstructionString;
- bInfo.ulFlags = ulFlags;
- bInfo.lpfn = BrowseCallbackProc;
- bInfo.lParam = 0;
- if ((pidl = ::SHBrowseForFolder(&bInfo)) == NULL)
- {
-
- return FALSE;
- }
- if (::SHGetPathFromIDList(pidl, FilePath) == FALSE)
- {
-
- return FALSE;
- }
- return TRUE;
- }
- TCHAR* GetGuidString()
- {
- GUID guid;
- static TCHAR szBuf[64] = {0};
- memset(szBuf, 0, 64*sizeof(TCHAR));
- CoInitialize(NULL);
- if (S_OK == ::CoCreateGuid(&guid))
- {
- _stprintf_s(szBuf, 64, _T("{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}"),
- guid.Data1,
- guid.Data2,
- guid.Data3,
- guid.Data4[0],
- guid.Data4[1],
- guid.Data4[2],
- guid.Data4[3],
- guid.Data4[4],
- guid.Data4[5],
- guid.Data4[6],
- guid.Data4[7]
- );
- }
- CoUninitialize();
- return szBuf;
- }
- DWORD GetSoftRunTime()
- {
- DWORD id;
- TCHAR HKey[50] = "ffffffff",LKey[50]="ffffffff";
- TCHAR OutTime[50];
- TCHAR DevicePath[ 260];
- if(FindPort(0,DevicePath)!=0)
- return 0;
-
- TCHAR year[10],month[10],day[10],hour[10],minute[10],second[10];
- ReadTimeAuthFromEprom(HKey,LKey, OutTime, &id, 30128, HKey, LKey, DevicePath);
- CString str=OutTime;
- CString temp="年";
- int pos=str.Find (temp);
- temp=str.Left (pos);
- str=str.Right (str.GetLength ()-pos-2);
- strcpy_s(year, temp.GetBuffer (0));temp.ReleaseBuffer ();
- temp="月";
- pos=str.Find (temp);
- temp=str.Left (pos);
- str=str.Right (str.GetLength ()-pos-2);
- strcpy_s(month, temp.GetBuffer (0));temp.ReleaseBuffer ();
- temp="日";
- pos=str.Find (temp);
- temp=str.Left (pos);
- str=str.Right (str.GetLength ()-pos-2);
- strcpy_s(day, temp.GetBuffer (0));temp.ReleaseBuffer ();
- temp="小时";
- pos=str.Find (temp);
- temp=str.Left (pos);
- str=str.Right (str.GetLength ()-pos-4);
- strcpy_s(hour, temp.GetBuffer (0));temp.ReleaseBuffer ();
- temp="分钟";
- pos=str.Find (temp);
- temp=str.Left (pos);
- str=str.Right (str.GetLength ()-pos-4);
- strcpy_s(minute, temp.GetBuffer (0));temp.ReleaseBuffer ();
- temp="0";
- strcpy_s(second, temp.GetBuffer (0));temp.ReleaseBuffer ();
- long time1=ConvertStringToTimerReal(year, month, day, hour, minute, second);
- GetRunTimer(year, month, day, hour, minute, second, DevicePath);
- long time2=ConvertStringToTimerReal(year, month, day, hour, minute, second);
-
- return time1 - time2;
- }
- void WriteTextLog(const TCHAR *format, ...)
- {
- try
- {
- static ThreadSection _critSection;
- AutoThreadSection aSection(&_critSection);
-
- TCHAR szlogpath[MAX_PATH] = {0};
- static TCHAR szModulePath[MAX_PATH] = {0};
- static TCHAR szFna[_MAX_DIR] = { 0 };
- if ( szModulePath[0] == _T('\0') )
- {
- TCHAR szDrive[_MAX_DRIVE] = { 0 };
- TCHAR szDir[_MAX_DIR] = { 0 };
- TCHAR szExt[_MAX_DIR] = { 0 };
- ::GetModuleFileName(NULL, szModulePath, sizeof(szModulePath) / sizeof(TCHAR));
- _tsplitpath_s(szModulePath, szDrive, szDir, szFna, szExt);
- _tcscpy_s(szModulePath, szDrive);
- _tcscat_s(szModulePath, szDir);
- }
- _stprintf_s(szlogpath, _T("%s日志\\%s%s.txt"), szModulePath, szFna, CTime::GetCurrentTime().Format("[%Y-%m-%d]").GetString());
-
- CStdioFile fp;
- if (PathFileExists(szlogpath))
- {
- if (fp.Open(szlogpath, CFile::modeWrite) == FALSE)
- {
- return;
- }
- fp.SeekToEnd();
- }
- else
- {
- if ( !fp.Open(szlogpath, CFile::modeCreate | CFile::modeWrite) )
- return;
- }
-
- TCHAR* old_locale = _tcsdup(_tsetlocale(LC_CTYPE, NULL));
- _tsetlocale(LC_CTYPE, _T("chs"));
-
- va_list args = NULL;
- int len = 0;
- TCHAR *buffer = NULL;
- va_start( args, format );
-
- len = _vsctprintf_p( format, args );
- if ( len == -1 )
- {
- goto clear;
- }
- len++;
- buffer = (TCHAR*)malloc( len * sizeof(TCHAR) );
- _vstprintf_s( buffer, len, format, args );
-
-
- fp.WriteString( CTime::GetCurrentTime().Format(_T("%Y-%m-%d %H:%M:%S ")) );
- fp.WriteString(buffer);
- fp.WriteString(_T("\n"));
-
- free( buffer );
- clear:
- _tsetlocale(LC_CTYPE, old_locale);
- free(old_locale);
- fp.Close();
- }
- catch (CException *e)
- {
- e->ReportError();
- e->Delete();
- }
- }
- BOOL ExectueScript(IN LPCTSTR lpCatalogSvr, IN LPCTSTR lpCatalogUser, IN LPCTSTR lpCatalogPsw, IN LPCTSTR lpScriptFile, IN LPCTSTR lpCatalogLog)
- {
-
- if ( lpCatalogSvr == NULL || lpCatalogSvr[0] == _T('\0') ||
- lpCatalogUser == NULL || lpCatalogUser[0] == _T('\0') ||
- lpCatalogPsw == NULL || lpCatalogPsw[0] == _T('\0') ||
- lpScriptFile == NULL || lpScriptFile[0] == _T('\0') || !PathFileExists(lpScriptFile) ||
- lpCatalogLog == NULL || lpCatalogLog[0] == _T('\0') )
- {
- WriteTextLog(_T("%s-%d-%s:参数无效!"),__FILE__, __LINE__, __FUNCTION__);
- return FALSE;
- }
- SHELLEXECUTEINFO stuExecInfo = { 0 };
- DWORD dwExitCode = STILL_ACTIVE;
- CString strCommandLine;
- strCommandLine.Format(_T(" -S %s -U %s -P %s -d master -i \"%s\" -o \"%s\""), lpCatalogSvr, lpCatalogUser, lpCatalogPsw, lpScriptFile, lpCatalogLog);
- stuExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
- stuExecInfo.lpFile = _T("sqlcmd");
- stuExecInfo.lpParameters = strCommandLine;
- stuExecInfo.nShow = SW_HIDE;
- stuExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
- if (!ShellExecuteEx(&stuExecInfo))
- {
- WriteTextLog(_T("执行ShellExecuteEx失败,错误码:%d"), GetLastError());
- return FALSE;
- }
- HANDLE hProcess = stuExecInfo.hProcess;
- if ( hProcess != NULL )
- {
- WaitForSingleObject(hProcess,INFINITE);
- CloseHandle(hProcess);
- }
- return TRUE;
- }
- BOOL ExectueStatement(IN LPCTSTR lpCatalogSvr, IN LPCTSTR lpCatalogUser, IN LPCTSTR lpCatalogPsw, IN LPCTSTR lpCatalogName, IN LPCTSTR lpSQLScript, IN LPCTSTR lpCatalogLog, IN const DWORD& dwQueryTimeOut )
- {
-
- if ( lpCatalogSvr == NULL || lpCatalogSvr[0] == _T('\0') ||
- lpCatalogUser == NULL || lpCatalogUser[0] == _T('\0') ||
- lpCatalogPsw == NULL || lpCatalogPsw[0] == _T('\0') ||
- lpCatalogName == NULL || lpCatalogName[0] == _T('\0') ||
- lpSQLScript == NULL || lpSQLScript[0] == _T('\0') ||
- lpCatalogLog == NULL || lpCatalogLog[0] == _T('\0') )
- {
- WriteTextLog(_T("%s-%d-%s:参数无效!"),__FILE__, __LINE__, __FUNCTION__);
- return FALSE;
- }
- SHELLEXECUTEINFO stuExecInfo = { 0 };
- DWORD dwExitCode = STILL_ACTIVE;
- CString strCommandLine;
- strCommandLine.Format(_T(" -S %s -U %s -P %s -d %s -Q \"%s\" -t %d -o %s"), lpCatalogSvr, lpCatalogUser, lpCatalogPsw, lpCatalogName, lpSQLScript, dwQueryTimeOut, lpCatalogLog);
- stuExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
- stuExecInfo.lpFile = _T("sqlcmd");
- stuExecInfo.lpParameters = strCommandLine;
- stuExecInfo.nShow = SW_HIDE;
- stuExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
- if (!ShellExecuteEx(&stuExecInfo))
- {
- WriteTextLog(_T("执行ShellExecuteEx失败,错误码:%s"), GetErrorInfo(GetLastError()));
- return FALSE;
- }
- HANDLE hProcess = stuExecInfo.hProcess;
- if ( hProcess != NULL )
- {
- WaitForSingleObject(hProcess,INFINITE);
- CloseHandle(hProcess);
- }
- if ( !PathFileExists(lpCatalogLog) )
- {
- WriteTextLog(_T("执行sqlcmd无日志文件返回"));
- return FALSE;
- }
- return TRUE;
- }
- BOOL IsCatalogDamage()
- {
- CString strInfo;
- strInfo.Format(_T("dbcc checkdb('%s')"), g_szDBName);
- if ( ExectueStatement(g_szDBSource, g_szDBAccount, g_szDBPassWord, _T("master"), strInfo, _T("sqlerr"), g_dwCheckdbTimeOut ? g_dwCheckdbTimeOut : 30) )
- {
- struct stat statbuf;
- stat(_T("sqlerr"), &statbuf);
- if ( statbuf.st_size == 0 )
- {
- WriteTextLog(_T("执行sqlcmd日志文件长度0"));
- return FALSE;
- }
- TCHAR *perr = new TCHAR[statbuf.st_size+1];
- memset(perr, 0, statbuf.st_size+1);
- FILE *err = NULL;
- _tfopen_s(&err, _T("sqlerr"), _T("r"));
- if ( err )
- {
- fread_s(perr, statbuf.st_size, sizeof(TCHAR), statbuf.st_size, err);
- fclose(err);
- }
- else
- {
- WriteTextLog(_T("打开sqlcmd日志文件失败:%s"), GetErrorInfo(GetLastError()));
- return FALSE;
- }
- strInfo = perr;
- if ( perr )
- delete []perr;
- if ( !strInfo.IsEmpty() )
- {
- CString strFind;
- strFind.Format(_T("CHECKDB 在数据库 '%s' 中发现 0 个分配错误和 0 个一致性错误。"),g_szDBName);
- if ( -1 == strInfo.Find(strFind) )
- {
-
- WriteTextLog(_T("sqlerr未找到匹配信息:%s"), strFind);
- return TRUE;
- }
- }
- }
- else
- {
- WriteTextLog(_T("执行dbcc checkdb失败"));
- }
- return FALSE;
- }
- DWORD WINAPI CheckdbThread(LPVOID lpParamter)
- {
-
- g_bIsCatalogDamage = IsCatalogDamage();
- return 0;
- }
- BOOL GetAllCatalogName( )
- {
- g_AryAllCatalogName.RemoveAll();
- CDatabase tagMaster;
- 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);
- }
- tagMaster.OpenEx(szConnectString, CDatabase::noOdbcDialog);
- }
- catch (CDBException * e)
- {
- #ifdef _DEBUG
- e->ReportError();
- #endif
- WriteTextLog(_T("打开数据库失败:%s"), e->m_strError);
- e->Delete();
- return FALSE;
- }
- try
- {
-
- CString strtmp = _T("");
- CRecordset tagRst(&tagMaster);
- tagRst.Open(CRecordset::forwardOnly, _T("select name From master.dbo.sysdatabases where sid <> 1"));
- while ( !tagRst.IsEOF() )
- {
- tagRst.GetFieldValue(_T("name"), strtmp);
- g_AryAllCatalogName.Add(strtmp);
- tagRst.MoveNext();
- }
- tagRst.Close();
- }
- catch (CDBException *e)
- {
- #ifdef _DEBUG
- e->ReportError();
- #endif
- WriteTextLog(_T("打开数据库失败:%s"), e->m_strError);
- e->Delete();
- return FALSE;
- }
- return TRUE;
- }
|